Swift's use of Uialertcontroller for Uiactionsheet

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.