2013-04-22 14 views

Odpowiedz

0

Próbowałem tego i przycisk Anuluj na dole:

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

Domyślnie Anuluj button is hidden, dodając Anuluj wola pokazuje go.

ALE: jeśli masz dodatkowe elementy GUI w swoim actionsheet trzeba

opcja1) tych pozycji, aby ukryć inne przyciski (aby mieć przestrzeń dla elementu GUI). Jego uszczypnąć, ale może pracować w jakiejś sytuacji lub

opcja2) trzeba ręcznie dodać przycisk do actionsheet

Actionsheet wbudowanego w przyciski nie są ALIGN-stanie dołu swobodnie, ponieważ w celu jest inny dla tego wbudowanego elementu GUI.

Zobacz to: Adding UIPickerView to UIActionSheet (buttons at the bottom)

+0

to działa bo u mają kilka innych przycisków przycisk powyżej anulować. Ale w moim przypadku nie mam innego przycisku. jest to tylko przycisk tableview i cancel – Arun

+0

W końcu rozumiem twoją konfigurację, więc myślę, że jedyną opcją dla ciebie jest dodanie UIButton do twojego ActionSheet. – nzs

+0

masz rację ... lepiej dla tej opcji :-) – Arun

6

to jest praca dla mnie:

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

Masz rację. Jeśli używasz 'addButtonWithTitle:' zamiast dbać o to wszystko przy pomocy inicjalizatora, musisz podać indeks przycisku anulowania. –

0

przykład w Swift:

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") 
    } 
} 
Powiązane problemy