简体   繁体   English

为什么UIActionSheet会取消我的应用程序崩溃?

[英]Why does UIActionSheet cancel crash my App?

I try to use the UIActionSheet within my iPhone App but have the following problem. 我尝试在我的iPhone应用程序中使用UIActionSheet但有以下问题。 When I tap the cancel button "I don't", the app crashes. 当我点击取消按钮“我没有”时,应用程序崩溃。 When I remove the NSLog statement from the actionSheet:clickedButtonAtIndex: it does not. 当我从actionSheet中删除NSLog语句时:clickedButtonAtIndex:它没有。 The "Yes, do it" button works just fine and I see the log statement in the console. “是的,做它”按钮工作得很好,我在控制台中看到了日志语句。 What's wrong? 怎么了?

- (void) doItWithConfirm {

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"do you really wanna do it?" 
                            delegate:self cancelButtonTitle:@"I don't" destructiveButtonTitle: nil
                            otherButtonTitles:@"Yes, do it", nil];

    [actionSheet showInView:self.view];
    [actionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    NSLog(@"buttonIndex: %@", buttonIndex);
}
NSLog(@"buttonIndex: %@", buttonIndex);

buttonIndex is an integer, and the %@ only expects ObjC objects (not integers). buttonIndex是一个整数, %@只需要ObjC对象(不是整数)。 This mismatch make the system crashes. 这种不匹配会导致系统崩溃。 Use 采用

NSLog(@"buttonIndex: %d", buttonIndex);

instead. 代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM