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用のimコーディングで、これが使用される方法です。ボタンに必要なタイトルを他のボタンセクションに追加するだけです。

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 に答える