20

我有这个代码:

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.

因为那肯定会有所帮助。

有任何想法吗?

谢谢!

4

2 回答 2

52

您可以在 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"];
于 2010-03-11T07:07:18.467 回答
-4

我为 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];
于 2011-12-01T21:54:06.713 回答