【发布时间】:2011-10-25 21:11:39
【问题描述】:
我在一个类中有以下代码,虽然当视图即将消失时警报确实出现在 UI 中(使用 iOS SDK 5.0),但永远不会调用 clickedButtonAtIndex 方法并且应用程序以“EXC_BAD_ACCESS”结束。我验证了视图确实/正在使用我的类作为委托。
代码在主线程上,在查看了关于这个主题的所有其他响应之后,我看不出为什么我的委托方法从未被调用。伙计们,我可以使用另一个线索。
@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);
}
【问题讨论】:
标签: ios5 uialertview