here's un campione con due azioni più un ok-action:
import UIKit
// The UIAlertControllerStyle ActionSheet is used when there are more than one button.
@IBAction func moreActionsButtonPressed(sender: UIButton) {
let otherAlert = UIAlertController(title: "Multiple Actions", message: "The alert has more than one action which means more than one button.", preferredStyle: UIAlertControllerStyle.ActionSheet)
let printSomething = UIAlertAction(title: "Print", style: UIAlertActionStyle.Default) { _ in
print("We can run a block of code.")
}
let callFunction = UIAlertAction(title: "Call Function", style: UIAlertActionStyle.Destructive, handler: myHandler)
let dismiss = UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: nil)
// relate actions to controllers
otherAlert.addAction(printSomething)
otherAlert.addAction(callFunction)
otherAlert.addAction(dismiss)
presentViewController(otherAlert, animated: true, completion: nil)
}
func myHandler(alert: UIAlertAction){
print("You tapped: \(alert.title)")
}
}
con vale a dire Gestore : myHandler si definisce una funzione, per leggere il risultato di il lasciare printSomething.
Questo è solo uno modo ;-)
Tutte le domande?
fonte
2016-06-26 20:15:46
Qual è la tua domanda? Che cosa hai provato, quali problemi ha avuto e cosa hai trovato durante il tentativo di eseguire il debug di questi problemi? – NobodyNada