【问题标题】:clickedButtonAtIndex method is not called未调用 clickedButtonAtIndex 方法
【发布时间】:2011-05-18 16:08:16
【问题描述】:

当用户单击UIAlertView 上的按钮时,应该调用clickedButtonAtIndex 方法,但是它不会:

.h 中我调用了UIAlertView 协议:

@interface RechercherViewController : UIViewController<UIAlertViewDelegate>  {

//code
}

.m 文件中我有这个:

-(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");
    }
}

日志文件中没有显示任何内容,请帮助,提前谢谢:)

【问题讨论】:

    标签: ios objective-c uialertview uialertviewdelegate


    【解决方案1】:

    delegate:nil 是问题所在。将self 作为代理传递给initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:

    【讨论】:

      【解决方案2】:

      您将 nil 作为委托参数传递。改为传递self

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-31
        • 1970-01-01
        相关资源
        最近更新 更多