如何创建“otherButtonTitles”?

发布于 2024-08-16 03:49:40 字数 169 浏览 2 评论 0原文

我让 AlertView 与“cancelButtonTitle:@“Cancel””和“otherButtonTitles:nil”完美配合。我的问题是如何获得其他按钮。

当我只更改“otherButtonTitles:@”2nd Button””时,iPhone 模拟器就会从应用程序中崩溃并进入主屏幕。

I have the AlertView working perfectly with a "cancelButtonTitle:@"Cancel"" and "otherButtonTitles:nil". My question is how to get other buttons.

When I only change the "otherButtonTitles:@"2nd Button"", then the iPhone simulator just crashes out of the app and into the homescreen.

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

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

发布评论

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

评论(2

×眷恋的温暖 2024-08-23 03:49:40

您希望像这样结束方法调用:

... cancelButtonTitle:@"Cancel" otherButtonTitles:@"Button1Title", @"Button2Title", nil];

这与您在 String 中看到的模式相同格式化,其中参数列表可以是任意长度。通常参数列表以 nil 结尾。不要忘记零。

You want to end your method call like this:

... cancelButtonTitle:@"Cancel" otherButtonTitles:@"Button1Title", @"Button2Title", nil];

This is the same pattern you see in String formatting, where the list of arguments can be of any length. Usually the argument list is then nil-terminated. Don't forget the nil.

陪我终i 2024-08-23 03:49:40

完全就像 Kevin 所说的,但作为补充,您还可以将目标操作分配给其他按钮。

当您实例化 UIAlertView 时,将 delegate 参数设置为 self,然后将以下方法添加到您的对象:

-(void) alertView: ( UIAlertView *) alertView 
         clickedButtonAtIndex: ( NSInteger ) buttonIndex {
      // do stuff
      // if you want the alert to close, just call [ alertView release ]   
}

`

Exactly like Kevin said, but as an addendum to that, you can also assign target-actions to the other buttons.

When you instantiate the UIAlertView, set the delegate argument to self, then add the following method to your object:

-(void) alertView: ( UIAlertView *) alertView 
         clickedButtonAtIndex: ( NSInteger ) buttonIndex {
      // do stuff
      // if you want the alert to close, just call [ alertView release ]   
}

`

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文