[Swift] Uikit Learning Warning Box: Uialertcontroller and Uialertview

Source: Internet
Author: User
Tags deprecated 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.

Using Uialertview in Xcode7 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, unifying the concept of alert at the system level-either in modal or PopOver mode.

?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 //  ViewController.swiftimport UIKitclassViewController: UIViewController {    override func viewDidLoad() {        super.viewDidLoad()        // Do any additional setup after loading the view, typically from a nib.                //创建一个Button        let button = UIButton(type: UIButtonType.Custom) //初始化UIButton        button.frame = CGRectMake(50, 100, 150, 50) //创建一个CGRect, 设置位置和大小        button.backgroundColor = UIColor.greenColor() //设置背景色        button.setTitle("点击显示弹窗", forState: UIControlState.Normal) //设置标题        //传递触摸对象(点击事件)        button.addTarget(self, action: "buttonPressed:", forControlEvents: UIControlEvents.TouchUpInside)        self.view.addSubview(button)            }    // Action    func buttonPressed(sender: UIButton) {        showAlertReset()       }        func showAlertDefault(){        let alertController = UIAlertController(title: "弹窗标题", message: "Hello, 这个是UIAlertController的默认样式", preferredStyle: UIAlertControllerStyle.Alert)                let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel, handler: nil)        let okAction = UIAlertAction(title: "好的", style: UIAlertActionStyle.Default, handler: nil)        let resetAction = UIAlertAction(title: "重置", style: UIAlertActionStyle.Destructive, handler: nil)                alertController.addAction(resetAction)                alertController.addAction(cancelAction)        alertController.addAction(okAction)                self.presentViewController(alertController, animated: true, completion: nil)    }        func showAlertReset(){        let alertControl = UIAlertController(title: "弹窗的标题", message: "Hello,showAlertReset ", preferredStyle: UIAlertControllerStyle.Alert)        let cancelAction = UIAlertAction(title: "取消操作", style: UIAlertActionStyle.Destructive, handler: nil)        let okAction     = UIAlertAction(title: "好的", style: UIAlertActionStyle.Default, handler: nil)        alertControl.addAction(cancelAction)        alertControl.addAction(okAction)        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.