In the IOS8 Uiactionsheet is discarded, we will choose Uialertcontroller to implement Uiactionsheet. This blog post will implement Uialertview to achieve uiactionsheet effect.
Specific steps:
1, create a actionsheet type of uialertcontroller;
2. Create two methods for the Uialertcontroller created in 1, in this example, create an Add method: Addaction () and a Delete method deleteaction ();
3, create a cancellation method, the parameter style type is cancel;
4. Add the methods created in steps 2 and 3 to the Uialertcontroller created in 1;
5. Use the modal view to launch the Uialertcontrller created in 1.
The specific code is implemented as follows:
</pre><pre name= "code" class= "HTML" > @IBAction func showactionsheet ( Sender:anyobject) {println ("Show action sheet") Let Optionmenu = Uialertcontroller (title:nil, message: "Select Choose ", Preferredstyle:. Actionsheet) Let deleteaction = uialertaction (title: "Delete", Style:.) Default, handler:{(alert:uialertaction!), Void in println ("delete")}) Let Saveaction = uialertaction (title: "Save", Style:.) Default, Handler: {(alert:uialertaction!), Void in println ("Save")}) Le T cancelaction = uialertaction (title: "Cancel", Style:.) Cancel, Handler: {(alert:uialertaction!), Void in println ("Cancel")}) opt Ionmenu.addaction (saveaction) optionmenu.addaction (deleteaction) optionmenu.addaction (cancelAction) Self.presentviewcontroller (Optionmenu, Animated:true, Completion:nil)}
The effect is as follows:
Note: Recently learning Swift in conjunction with the Foreign Swift development website, insist on daily Swift translation and write it in blog form.
Swift's use of Uialertcontroller for Uiactionsheet