iOS 8 after the official Apple recommended the use of Uialertcontroller this class, so specifically to find information online, understand the usage, write a code, record!
Thank you, turn from: http://www.hangge.com/blog/cache/detail_651.html
1. Create a Alertview
Overridefunc viewdidappear (animated:bool) {super.viewdidappear (animated) let Alertcontroller= Uialertcontroller (title:"System Tips", message:"Are you sure you want to leave hangge.com? ", Preferredstyle:. Alert) Let Cancelaction= Uialertaction (title:"Cancel", Style:. Cancel, Handler:nil) let Okaction= Uialertaction (title:"yes, okay.", Style:. Default, Handler: {actioninchPrint ("clicked OK.")}) alertcontroller.addaction (cancelaction) alertcontroller.addaction (okaction) self.pres Entviewcontroller (Alertcontroller, animated:true, Completion:nil)}
2. Create a Actionsheet
(Note: If there is a "cancel" button on the menu, it will always appear in the menu, regardless of the order in which it was added)
Let Alertcontroller = Uialertcontroller (title:"Save or delete data", Message:"Delete data will not be recoverable", Preferredstyle:. Actionsheet) Let Cancelaction= Uialertaction (title:"Cancel", Style:. Cancel, Handler:nil) let Deleteaction= Uialertaction (title:"Delete", Style:. Destructive, Handler:nil) let Archiveaction= Uialertaction (title:"Save", Style:. Default, Handler:nil) alertcontroller.addaction (cancelaction) alertcontroller.addaction (deleteaction) Alertcontroller.addaction (archiveaction) Self.presentviewcontroller (Alertcontroller, animated:true, Completion:nil)
3, button use warning mode, text color change, used to alert users
var " yes, okay. ", Style:UIAlertActionStyle.Destructive, Handler:nil)
4. Add any number of text input boxes
Overridefunc viewdidappear (animated:bool) {super.viewdidappear (animated) let Alertcontroller= Uialertcontroller (title:"System Login", message:"Please enter user name and password", PreferredStyle:UIAlertControllerStyle.Alert) Alertcontroller.addtextfieldwithconfigurationhandler { (Textfield:uitextfield!) -VoidinchTextfield.placeholder="User name"} alertcontroller.addtextfieldwithconfigurationhandler {(Textfield:uitextfield!) -VoidinchTextfield.placeholder="Password"Textfield.securetextentry=true} alertcontroller.addtextfieldwithconfigurationhandler {(Textfield:uitextfield)->voidinchTextfield.placeholder="Duplicate Password"Textfield.securetextentry=trueprint (Textfield.text)} Let Cancelaction= Uialertaction (title:"Cancel", Style:. Cancel, Handler:nil) let Okaction= Uialertaction (title:"yes, okay.", Style:. Default, Handler: {actioninch //you can also get TextField let login = alertcontroller.textfields! in the form of subscript [0]Let login = alertcontroller.textfields!. first! asUitextfield Let password= alertcontroller.textfields!. last! asUitextfield Print ("User name: \ (login.text) password: \ (password.text)")}) alertcontroller.addaction (cancelaction) alertcontroller.addaction (okaction) self.pres Entviewcontroller (Alertcontroller, animated:true, Completion:nil)}
5. Use code to remove the prompt box
Self.presentedviewcontroller?. Dismissviewcontrolleranimated (false, Completion:nil)
The use of Swift-uialertcontroller