开发者

Why does UIActionSheet cancel crash my App?

开发者 https://www.devze.com 2022-12-26 21:45 出处:网络
I try to use the UIActionSheet within my iPhone App but have the following problem. When I tap the cancel button \"I don\'t\", the app crashes. When I remove the NSLog statement from the actionSheet:c

I try to use the UIActionSheet within my iPhone App but have the following problem. 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. 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 cancelButtonT开发者_Python百科itle:@"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). This mismatch make the system crashes. Use

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

instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号