2013-04-22 7 views

答えて

0

私はこれを試してみましたが、[キャンセル]ボタンを一番下にある:

menu = [[UIActionSheet alloc] initWithTitle:@"Actionsheet" 
                delegate:self 
             cancelButtonTitle:@"Cancel" 
            destructiveButtonTitle:@"destructive" 
             otherButtonTitles:@"other1", nil]; 
menu.actionSheetStyle = UIActionSheetStyleDefault; 
[menu addButtonWithTitle:@"Cancel"]; 

デフォルトではbutton is hiddenをキャンセルし、キャンセルされますを追加することを示しています。

しかし:あなたは

オプション1)これらは他のボタンを非表示に位置に持って(あなたのGUI要素のためのスペースを持っているあなたのactionsheetに追加のGUI要素を持っている場合)。その微調整が、いくつかの状況や

オプション2で作業することができます)手動actionsheetに

Actionsheetの内蔵ボタンをあなたのボタンを追加する必要が並ぶ-できていない下に自由に目的ので、この組み込みgui要素では異なります。それは私のための仕事ですAdding UIPickerView to UIActionSheet (buttons at the bottom)

+0

uは、他のボタンのカップルが上記キャンセルボタンを持っているので、この作品

はこれを参照してください。しかし、私の場合、他のボタンはありません。そのちょうどtableviewとキャンセルボタン – Arun

+0

最後に私はあなたの設定を理解しているので、私はあなたのActionSheetにUIButtonを追加することだと思う。 – nzs

+0

あなたは正しいです...私はそのオプションのために行くほうがいいです:-) – Arun

6

スウィフト

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"SomeTitle" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil]; 
[actionSheet addButtonWithTitle:@"Some Action"];   
[actionSheet addButtonWithTitle:@"Cancel"]; 
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons -1; 
+1

あなたは正しいです。 'addButtonWithTitle:'を使用してイニシャライザですべてを処理するのではなく、キャンセルボタンのインデックスを指定する必要があります。 –

0

例:

func presentMyActionSheetIOS7() { 
    let actionSheet: UIActionSheet = UIActionSheet(title: "What do you want to do?", delegate: self, cancelButtonTitle: nil, destructiveButtonTitle: nil) 

    actionSheet.addButtonWithTitle("Change Transparency") 
    actionSheet.addButtonWithTitle("Hide Photo") 
    actionSheet.addButtonWithTitle("Cancel") 
    actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1 

    actionSheet.showInView(self.view) 
} 

func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) { 
    switch buttonIndex { 
     case 0: 
      println("Change Transparency") 
     case 1: 
      println("Hide Photo") 
     case 2: 
      println("Cancel") 
     default: 
      println("Default") 
    } 
} 
関連する問題