我在一類下面的代碼,雖然警報會出現在UI(使用的是iOS SDK 5.0)當視圖即將消失,clickedButtonAtIndex方法不會被調用和該應用終止於「EXC_BAD_ACCESS」。我驗證了視圖是/將我的課程作爲代理使用。UIAlertView中內部viewWillDisappear並沒有叫clickedButtonAtIndex
代碼位於主線程上,在查看了關於此主題的所有其他響應之後,我無法明白爲什麼我的委託方法從未被調用過。我可以使用另一個線索人。
@interface ConnectionViewController : UIViewController <UIAlertViewDelegate> {
....
}
@implementation ConnectionViewController
...
- (void)viewWillDisappear:(BOOL)animated
{
connection = [Connection objectWithConnName:[connectionName text] host:[mtDevice text] user:[userName text] passwd:[userPassword text]];
BOOL result = [connection test];
if (result) {
[[FirstViewController sharedInstance] addConnection:connection];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"No Connection" message:@"Failed to connect to device" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ignore", @"Ok", nil];
[alert show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"clickedButtonAtIndex: %d",buttonIndex);
}
我知道它一定與阻塞有關,謝謝! – tgunr