スレッド内で直接アラート表示をしてはいけない。
といってもiPhoneやiPadでは実害は無い。何故かiPad miniにおいてのみクラッシュしてしまう。
以下のようなアラート表示用の関数を用意し、
-(void)showAlertFromThread: (id)param
{
NSString *msg = (NSString*)param;
UIAlertView *alert = [
[UIAlertView alloc]
initWithTitle:@"Alert from thread"
message: [NSString stringWithFormat: @"message : %@",msg]
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil
];
[alert show];
}
スレッド内では以下のように呼び出せば解決できる。
[self performSelectorOnMainThread:@selector(showAlertFromThread:)
withObject:@"Hello" waitUntilDone:TRUE];
0 件のコメント:
コメントを投稿