您的位置:首页 > 移动开发 > IOS开发

ios学习之alertView的基本使用

2015-10-18 16:48 519 查看
在最新的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
具体看这个
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: