【发布时间】:2015-06-08 08:17:54
【问题描述】:
我有一个父类和 5 个子类。在这 5 个中,有 2 个类(子)我使用了 AlertView 并使用了警报委托方法。 在子类中,我有一个通用按钮,通过该按钮调用父类的警报委托。这是“注销”按钮。通过哪个父类的警报委托可以访问。所以会发生什么是我使用警报委托的类(在我的情况下有 2 个这样的类)父类的委托没有被调用。但是我没有使用来自那些类父类的委托的警报视图的类被调用。 我不知道我是否有道理,如果没有,请告诉我,我会再次尝试更好地解释。
//parent class
-(void)someMethod
{
UIAlertView * alertView =[[UIAlertView alloc]initWithTitle:ALERT_TITLE message:@"Are you sure want to logout?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil];
[alertView show];
}
// not getting called "only" when I have alert view in my sub class
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
[[AppDelegate appDelegate]logout];
[[AppDelegate appDelegate]saveWelComeBool:YES];
}
}
//sub class
ParentClass *parent = [[ParentClass alloc]init];
[parent someMethod];// method is getting called but not the alert delegate
-(void)someMethod2
{
UIAlertView * alertView =[[UIAlertView alloc]initWithTitle:ALERT_TITLE message:@"Are you sure want to logout?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil];
[alertView show];
}
//getting called
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
[[AppDelegate appDelegate]logout];
[[AppDelegate appDelegate]saveWelComeBool:YES];
}
}
【问题讨论】:
-
可能是
parent被释放了 -
将 - (void)dealloc { NSLog(@"%@", self);} 添加到 ParentClass,你会发现它被释放了
-
这适用于 iOS 8 吗?如果是这样,您无论如何都应该使用 UIAlertController。
标签: ios objective-c delegates uialertview