iPhone 中带有两个按钮的 UIAlertView

发布于 2024-09-13 13:07:07 字数 714 浏览 2 评论 0原文

我试图在按下按钮时显示警报视图,因此我编写了如下代码:

- (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];
}

但是此代码在 initWithTitle 方法中出现以下异常而崩溃:

2010-08-11 03:03:18.697 Polaris[1155:207] *** -[UIButton copyWithZone:]:无法识别的选择器发送到实例 0x176af0
2010-08-11 03:03:18.700 Polaris[1155:207] *** 由于未捕获的异常而终止应用程序

0x176af0 而终止应用程序与参数“sender”的值相同,即操作处理程序为“signUpComplete:”的按钮。我认为问题在于 otherButtonTitles: 参数,因为它与参数 nil 一起工作正常。所以创建“确定”按钮时遇到问题。 我的代码有什么问题吗?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

待天淡蓝洁白时 2024-09-20 13:07:42

otherButtonTitles 列表必须以 nil 结尾:

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

otherButtonTitles list must be nil-terminated:

UIAlertView* alert_view = [[UIAlertView alloc]
      initWithTitle: @"test" message: @"test" delegate: nil 
      cancelButtonTitle: @"cancel" otherButtonTitles: @"OK", nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文