UIAlertView委托没有被调用?

时间:2015-06-08 08:17:54

标签: ios objective-c delegates uialertview

我有一个父类和5个子类。在这5个类中有2个类(sub),其中我使用了AlertView并使用了alert委托方法。 在子类中,我有一个公共按钮,通过该按钮可以调用父类的警报委托。这是“退出”按钮。通过哪个父类'警报委托可访问。那么所发生的是我使用alert delegate的类(在我的例子中有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];
    }
}

3 个答案:

答案 0 :(得分:1)

从子类中删除alertView:clickedButtonAtIndex:方法。

如果您的第二个类是第一个类(Parent类)的子类,则不需要在子类中重新实现父类方法,除非您要添加一些额外的功能。由于第二类已经继承了所有父类方法。

因此,如果从子类中删除委托方法,则会自动调用父类方法。

答案 1 :(得分:0)

使用<UIAlertViewDelegate>而不是子类确认父类,然后将在父及其所有子类中调用alertView委托。请确保,您不会再次使用rails new app_name -m template_name.rb

重新确认子类

希望这有帮助。

答案 2 :(得分:0)

如果你定义 alertView:clickedButtonAtIndex:委托方法,那么我面临同样的问题,即超类和子类,那么超类方法就不会调用你必须从子类中删除委托方法

相关问题