[Swift] Uikit Learning Warning Box: Uialertcontroller and Uialertview

Source: Internet
Author: User
Tags deprecated set background uikit


Important: Uialertview is deprecated in IOS 8. (Note that uialertviewdelegate is also deprecated.) To create and manage alerts in IOS 8 and later, instead use Uialertcontroller with a preferredstyle ofuialertcontrollersty Lealert.


uialertview will report the following warning:  

' Uialertview ' was deprecated on IOS 9.0:uialertview is deprecated. Use Uialertcontroller with a preferredstyle of Uialertcontrollerstylealert instead? ?


Alert Views: Alert views display a concise and informative alert message to the user.

uialertcontroller  also replaces  UIAlertView  and  uiactionsheet, the concept of alert is unified at the system level-in the form of modal or popover.  

  viewcontroller.swiftimport uikitclass viewcontroller: uiviewcontroller {     override func viewdidload ()  {         super.viewdidload ()         // do any additional  setup after loading the view, typically from a nib.                 //Create a button         let button = uibutton (Type: uibuttontype.custom)   Initialize Uibutton        button.frame = cgrectmake (50, 100,  150, 50)  //Create a cgrect,  set location and size          Button.backgroundcolor = uicolor.greencolor ()  //Set background color          button.settitle ("Click to Show Pop-up Window",  forstate: uicontrolstate.normal)  //set the title         // Pass-Through Touch object (click event)         button.addtarget (self, action:  " buttonpressed: ",  forcontrolevents: uicontrolevents.touchupinside)          self.view.addsubview (Button)              }    // action    func buttonpressed (Sender:  uibutton)  {        showalertreset ()         }        func showalertdefault () {         let alertcontroller = uialertcontroller (title:  "pop-up window title",  message:  "hello,  This is the default style for Uialertcontroller", preferredstyle:  Uialertcontrollerstyle.alert)                 let cancelaction =  Uialertaction (title:  "Cancel",  style: uialertactionstyle.cancel, handler: nil)          let okaction = uialertaction (title:  "Good",  Style: uialertactionstyle.default, handler: nil)          let resetaction = uialertaction (title:  "Reset", style:  Uialertactionstyle.destructive, handler: nil)                  alertcontroller.addaction (resetaction)                  alertcontroller.addaction (cancelAction)         alertcontroller.addaction (okaction)                &nbSp; self.presentviewcontroller (Alertcontroller, animated: true, completion: nil)     }        func showalertreset () {         let alertcontrol = uialertcontroller (title:  " The title of the pop-up window ", message: " hello,showalertreset  ", preferredstyle:  Uialertcontrollerstyle.alert)         let cancelaction =  uialertaction (title:  "Cancel operation", style: uialertactionstyle.destructive, handler:  Nil)         let okAction     =  Uialertaction (title:  "good",  style: uialertactionstyle.default, handler: nil)          alertcontrol.addaction (cancelaction)          alertcontrol.addaction (okaction)   &nbsP;     self.presentviewcontroller (alertcontrol, animated: true,  Completion: nil)     }        override  Func didreceivememorywarning ()  {         Super.didreceivememorywarning ()         // Dispose of  any resources that can be recreated.    }}


Reference:

Http://www.jianshu.com/p/86f933850df8

http://blog.csdn.net/xiaowenwen1010/article/details/40108097



[Swift] Uikit Learning Warning Box: Uialertcontroller and Uialertview

Related Article

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.