clickedButtonAtIndex method is not called

安稳与你 提交于 2019-12-02 18:28:14

问题


when the user click on a button on the UIAlertView the clickedButtonAtIndex method is supposed to be called, however, it doesn't :

in the .h i have called the UIAlertView protocol :

@interface RechercherViewController : UIViewController<UIAlertViewDelegate>  {

//code
}

and in .m file i have this :

-(void)requestFailed:(ASIHTTPRequest *)request
{
    //quand il y aura un échec lors de l'envoie de la requête

    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"TopStation"
                                                message :@"Your internet connexion is down"
                                                delegate:nil
                                       cancelButtonTitle:@"OK"
                                       otherButtonTitles:nil];

                       [alert show];
                       [alert release];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex == 0) {
        NSLog(@"buttonIndex 0");
    } else if(buttonIndex == 1) {
        NSLog(@"buttonIndex 1");
    }
}

nothing is shown in the log file, please help, thx in advance :)


回答1:


delegate:nil is the problem. Pass self as the delegate to initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:.




回答2:


You're passing nil as the delegate argument. Pass self instead.



来源:https://stackoverflow.com/questions/6047698/clickedbuttonatindex-method-is-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!