如何向现有的 UIActionSheet 添加按钮?

发布于 2024-08-24 12:21:14 字数 741 浏览 5 评论 0原文

我有这段代码:

UIActionSheet *actionSheet = [[[UIActionSheet alloc]
                initWithTitle:@"Illustrations"
                delegate:self
                cancelButtonTitle:@"Cancel"
                destructiveButtonTitle:nil
                otherButtonTitles: @"ABC", @"XYZ",
                nil] autorelease];
UIImage *image = // whatever, snip
if (image != nil)
{
    [actionSheet addButtonWithTitle:@"LMNOP"];
}

它在有条件地添加我的 LMNOP 按钮方面做得很好。

...取消按钮之后。

如何使用条件按钮构建操作表?可悲的是,我不能这样做:

UIActionSheet *actionSheet = [[[UIActionSheet alloc]
      // ... etc.
      otherButtonTitles: someMutableArray
      // ... etc.

因为那肯定会有帮助。

有什么想法吗?

谢谢!

I have this code:

UIActionSheet *actionSheet = [[[UIActionSheet alloc]
                initWithTitle:@"Illustrations"
                delegate:self
                cancelButtonTitle:@"Cancel"
                destructiveButtonTitle:nil
                otherButtonTitles: @"ABC", @"XYZ",
                nil] autorelease];
UIImage *image = // whatever, snip
if (image != nil)
{
    [actionSheet addButtonWithTitle:@"LMNOP"];
}

and it does a great job of adding my LMNOP button conditionally.

...AFTER the cancel button.

How can I construct my action sheet with a conditional button? Sadly, I can't do:

UIActionSheet *actionSheet = [[[UIActionSheet alloc]
      // ... etc.
      otherButtonTitles: someMutableArray
      // ... etc.

because that would certainly help.

Any ideas?

Thanks!

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

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

发布评论

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

评论(2

情定在深秋 2024-08-31 12:21:14

您可以在 init 方法之后添加所有按钮。

UIActionSheet* sheet = [[[UIActionSheet alloc] init] autorelease];
sheet.title = @"Illustrations";
sheet.delegate = self;
[sheet addButtonWithTitle:@"ABC"];
[sheet addButtonWithTitle:@"XYZ"];
if (condition)
    [sheet addButtonWithTitle:@"LMNOP"];
sheet.cancelButtonIndex = [sheet addButtonWithTitle:@"Cancel"];

You can add all buttons after the init method.

UIActionSheet* sheet = [[[UIActionSheet alloc] init] autorelease];
sheet.title = @"Illustrations";
sheet.delegate = self;
[sheet addButtonWithTitle:@"ABC"];
[sheet addButtonWithTitle:@"XYZ"];
if (condition)
    [sheet addButtonWithTitle:@"LMNOP"];
sheet.cancelButtonIndex = [sheet addButtonWithTitle:@"Cancel"];
爱人如己 2024-08-31 12:21:14

我正在为 iOS 4 进行编码,这就是使用的方法。您只需在 otherbutton 部分中添加所需的按钮标题即可。

UIActionSheet *phoneActionSheet = [[UIActionSheet alloc]
                                          initWithTitle:@"Do you want to call or text this person?"
                                          delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          destructiveButtonTitle:@"Call"                                            
                                          otherButtonTitles:@"Text",nil];

im coding in for iOS 4 and this is the method that is used. You just add the title you want for the button in the otherbutton sections.

UIActionSheet *phoneActionSheet = [[UIActionSheet alloc]
                                          initWithTitle:@"Do you want to call or text this person?"
                                          delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          destructiveButtonTitle:@"Call"                                            
                                          otherButtonTitles:@"Text",nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文