简体   繁体   中英

UIAlertView with two buttons in iPhone

I'm trying show an alert view when a button was pressed, so I wrote code as follows:

- (IBAction)signUpComplete: (id)sender {
  UIAlertView* alert_view = [[UIAlertView alloc]
      initWithTitle: @"test" message: @"test" delegate: nil cancelButtonTitle: @"cancel" otherButtonTitles: @"OK"];
  [alert_view show];
  [alert_view release];
}

But this code crashes with the following exception in the initWithTitle method:

2010-08-11 03:03:18.697 Polaris[1155:207] *** -[UIButton copyWithZone:]: unrecognized selector sent to instance 0x176af0
2010-08-11 03:03:18.700 Polaris[1155:207] *** Terminating app due to uncaught exception

0x176af0 is the same as the value of the argument 'sender', which is the button whose action handler is signUpComplete:. I think the problem is the otherButtonTitles: parameter, because it works fine with the argument nil. So it has a problem with creating the OK button. Is there anything wrong with my code?

Thanks!

otherButtonTitles list must be nil-terminated:

UIAlertView* alert_view = [[UIAlertView alloc]
      initWithTitle: @"test" message: @"test" delegate: nil 
      cancelButtonTitle: @"cancel" otherButtonTitles: @"OK", nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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