接続を待っているアプリケーションがあります。アプリケーションが待機している間、プログラムによって、またはユーザーが AlertView のキャンセル ボタンをクリックすることによって、AlertView をユーザーに表示する必要があります。
メインスレッドはクライアントが接続するのを待っています。別のスレッドのように、ダイアログの時間を更新している AlertView を作成して表示しています。スレッドには、AlertView のテキストを更新する has NSRunLoop があります。
AlertView がタッチ イベントを受信せず、プログラムで却下されないことを除いて、すべて正常に動作します。ここで私が間違っているかもしれないことに誰かが光を当てることができますか.
これがサンプルコードです。
funcA() {
[NSThread detachNewThreadSelector:@selector(createDialog) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(updateDialog) toTarget:self withObject:nil];
..
..
BlockingWait();
..
..
}
- (void) createDialog {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
alert = [[UIAlertView alloc] initWithTitle:@"Wait" message:@"\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
...
label = [[UILabel alloc] initWithFrame:CGRectMake(30.0f, 20.0f, 225.0f, 90.f)];
[alert show];
[alert release];
[pool drain];
}
- (void) upDateDialog {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSRunLoop *loop = [NSRunLoop currentRunLoop];
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateText) userInfo:nil repeats:YES];
[loop run];
[pool drain];
}
- (void) updateText {
label.text = " Wait for" + n + "secs";
n--;
if ( n == 0 )
[alert dismissWithClickedButtonIndex:0 animated:YES]; // Doesn't work
}
- (void) alertView: (UIAlertView *) alert clickedButtonAtIndex:(NSInteger) buttonIndex {
// Never Gets called
NSLog(@"Alert is dissmissed with button index %d", buttonIndex);
if (buttonIndex == 0) {
[timer invalidate];
}
}