Vorrei creare questo tipo di menu, ovviamente con altri pulsanti di menu. Esiste un viewcontroller predefinito che lo rappresenta, oppure devo ottenere immagini e crearlo da solo.Creazione di UIActionSheet
risposta
Date un'occhiata alla documentazione di UIActionSheet.
NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title
NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles
NSString *other1 = @"Other Button 1";
NSString *other2 = @"Other Button 2";
NSString *other3 = @"Other Button 3";
NSString *cancelTitle = @"Cancel Button";
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:actionSheetTitle
delegate:self
cancelButtonTitle:cancelTitle
destructiveButtonTitle:destructiveTitle
otherButtonTitles:other1, other2, other3, nil];
[actionSheet showInView:self.view];
Quello che stai cercando è chiamato un foglio di azioni. Per saperne di più qui http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIActionSheet_Class/Reference/Reference.html
È necessario utilizzare un UIActionSheet
.
Per prima cosa è necessario aggiungere UIActionSheetDelegate
al file ViewController.h.
Quindi è possibile fare riferimento a un actionsheet con:
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Select Sharing option:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:
@"Share on Facebook",
@"Share on Twitter",
@"Share via E-mail",
@"Save to Camera Roll",
@"Rate this App",
nil];
popup.tag = 1;
[popup showInView:self.view];
poi si deve gestire ciascuna delle chiamate.
- (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (popup.tag) {
case 1: {
switch (buttonIndex) {
case 0:
[self FBShare];
break;
case 1:
[self TwitterShare];
break;
case 2:
[self emailContent];
break;
case 3:
[self saveContent];
break;
case 4:
[self rateAppYes];
break;
default:
break;
}
break;
}
default:
break;
}
}
Questo è stato deprecato per iOS 8.x https://developer.apple.com/documentation/uikit/uialertcontroller#//apple_ref/occ/cl/UIAlertController
+! per essere l'unico a chiamarlo "UIActionSheet" (oltre a fornire una buona risposta). – rmaddy
Stavo letteralmente lavorando alla mia app mentre vedevo la domanda! Viene dal mio codice verbatim;) – ApolloSoftware
funziona anche senza aggiungere UIActionSheetDelegate .. Voglio sapere come ... – Nepster
Si chiama un UIActionSheet: Si crea uno in questo modo:
NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title
NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles
NSString *other1 = @"Other Button 1";
NSString *other2 = @"Other Button 2";
NSString *other3 = @"Other Button 3";
NSString *cancelTitle = @"Cancel Button";
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:actionSheetTitle
delegate:self
cancelButtonTitle:cancelTitle
destructiveButtonTitle:destructiveTitle
otherButtonTitles:other1, other2, other3, nil];
[actionSheet showInView:self.view];
Implementare l'UISctionSheetDelegate di rispondere all'azione pulsante.
Date un'occhiata a questo tutorial per maggiori informazioni: http://mobile.tutsplus.com/tutorials/iphone/uiactionsheet_uiactionsheetdelegate (Codice è da questo tutorial)
- 1. Visualizzazione di un UIActionSheet
- 2. Utilizzo di UIActionSheet su iPad
- 3. UIActionSheet iPad non visualizzato
- 4. come aggiungere UIPickerView in UIActionSheet
- 5. UIDatePicker in UIActionSheet stratificazione problema
- 6. Layout UIActionSheet errato nel popover
- 7. Presentazione di un UIPopover da un UIActionSheet
- 8. Come disattivare il pulsante in UIActionSheet?
- 9. Forzare UIActionSheet per utilizzare un orientamento specifico
- 10. UIActionSheet sul telaio iPad troppo piccolo
- 11. iPhone UIActionSheet auto-rotante non funzionante
- 12. Come utilizzare UIAlertController per sostituire UIActionSheet?
- 13. UIActionSheet annulla il pulsante non chiude il foglio di azioni
- 14. EXC_BAD_ACCESS quando si tenta di avviare UIActionSheet in Swift
- 15. Sviluppo iPhone: come creare sfondo colorato o traslucido per UIActionSheet?
- 16. Come aggiungere un pulsante a un UIActionSheet esistente?
- 17. iOS 8 UIActionSheet ignora vista supportedInterfaceOrientations controller e shouldAutorotate
- 18. UIAlertView e UIActionSheet non vengono visualizzati correttamente in iOS 8
- 19. Xcode iPad UIActionSheet con molti pulsanti non visualizzati correttamente iOS7
- 20. Come cambiare la sequenza del pulsante in UIActionsheet in iPhone?
- 21. Come si codifica un pulsante verde in UIActionSheet?
- 22. UIActionSheet iPad - Non viene visualizzato l'ultimo pulsante aggiunto
- 23. Inserire il pulsante Annulla in UIActionSheet nella parte inferiore
- 24. Mantieni/rilascia pattern per UIPopoverController, UIActionSheet e controller di visualizzazione modali?
- 25. Come posso inviare un array di stringhe in un metodo init varargs UIActionSheet?
- 26. iOS 5.1 + UISplitViewController in PortraitMode + UIActionSheet in MasterController = Errore di asserzione
- 27. creazione di file, creazione di directory in modo ricorsivo
- 28. Creazione di autorizzazioni personali
- 29. Creazione di riferimento null
- 30. Creazione griglia di esagoni
Il titolo e la popolarità di questa domanda è molto meglio del duplicato. Sarebbe bello riaprire questa domanda in modo da poter aggiungere risposte aggiornate. – Suragch
Vota per riaprire per favore. – Stunner
@ Suragch hai ragione. è più utile e comprensibile di altri link –