here's próbka z dwóch działań plus OK działania:
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)")
}
}
z tj handler: myHandler Użytkownik definiuje funkcję, aby odczytać wynik z let printSomething.
To tylko jeden way ;-)
Wszelkie pytania?
Jakie jest Twoje pytanie? Co próbowaliście, jakie mieliście problemy i co znaleźliście, próbując rozwiązać te problemy? – NobodyNada