ios学习之alertView的基本使用

来源:互联网 发布:四季彩软件下载 编辑:程序博客网 时间:2024/06/14 10:40

在最新的ios9中 使用AlertController来使用的 所以 如果要呈现的话 就只要self.presentViewController即可

alertview是一个警告框提示的作用,

需要用到的知识有


以下是具体的代码

class ViewController: UIViewController {//声明一个UIAlertController实例,以便在下方代码中进行调用    var controller: UIAlertController?    override func viewDidLoad() {        //创建一个alertcontroller的实例 最上面的标题,还有信息,以什么方式弹出这个警告框        controller = UIAlertController(title: "曹凯强", message: "爱我请点我", preferredStyle: UIAlertControllerStyle.Alert)        //创建在点击的时候该发生什么函数 action        let action = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default,handler: {(paramAction:UIAlertAction!) ->  Void in            print("nihao")            })              super.viewDidLoad()        // Do any additional setup after loading the view, typically from a nib.    }    //创建一个文本输入框    let action1 = UIAlertAction(title: "nihao", style: UIAlertActionStyle.Default) { (paramAction:UIAlertAction!) -> Void in        if let textField = self.controller.textFields{            let textFields = textField as [UITextField]        }    }                override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()        // Dispose of any resources that can be recreated.    }    //应该是在主视图加载完成之后再去显示这个视图,所以要重写这个函数    //viewDidAppear    override func viewDidAppear(animated: Bool) {        super.viewDidAppear(true)        //呈现这个controller的时候所用的方法        self.presentViewController(controller!, animated: true, completion: nil)    }}

http://www.hcxy.me/course/19/learn#lesson/237

具体看这个

0 0
原创粉丝点击