swift 的 UIAlertController使用
2015-12-12 12:50
489 查看
1.弹出带有取消和确定以及标题的alertController,并且附带UITextField
@IBAction func testAlert(sender: AnyObject) {
let alertController = UIAlertController(title: "提示", message: "哈哈哈,你懂的", preferredStyle:UIAlertControllerStyle.Alert);
let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel) { (action : UIAlertAction) -> Void in
print("点击了取消按钮");
}
let confirmAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default) { (action :UIAlertAction) -> Void in
print("点击了确定按钮");
}
alertController.addAction(cancelAction);
alertController.addAction(confirmAction);
alertController.addTextFieldWithConfigurationHandler { (textField : UITextField) -> Void in
//配合textField的代理方法使用
textField.placeholder = "请输入密码";
textField.secureTextEntry = true;
textField.tag = 111;
textField.delegate = self;
}
self.presentViewController(alertController, animated: true) { () -> Void in
print("已经弹出");
};
}
@IBAction func testAlert(sender: AnyObject) {
let alertController = UIAlertController(title: "提示", message: "哈哈哈,你懂的", preferredStyle:UIAlertControllerStyle.Alert);
let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel) { (action : UIAlertAction) -> Void in
print("点击了取消按钮");
}
let confirmAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default) { (action :UIAlertAction) -> Void in
print("点击了确定按钮");
}
alertController.addAction(cancelAction);
alertController.addAction(confirmAction);
alertController.addTextFieldWithConfigurationHandler { (textField : UITextField) -> Void in
//配合textField的代理方法使用
textField.placeholder = "请输入密码";
textField.secureTextEntry = true;
textField.tag = 111;
textField.delegate = self;
}
self.presentViewController(alertController, animated: true) { () -> Void in
print("已经弹出");
};
}
相关文章推荐
- iOS项目之Swift新闻App(三)—访问新闻详情
- Swift中的if语句使用where
- Swift -- 组合赋值运算符
- Swift注释风格
- Swift2.1-初始化
- Swift2.1-继承
- Swift应用开源项目推荐
- swift在github上开源的地址
- 初探swift语言的学习笔记九(OC与Swift混编)
- 关于OC与swift混编时-swift.h更新问题
- 关于swift,OC,C++混合编程(二)
- 关于swift,OC,C++混合编程(一)
- Swift 开源那点事儿
- Swift中编写单例的正确方式
- swift之mutating关键字
- swift分享到微信
- Swift:可选类型(optional)与构造函数
- The beginning iOS8 Programming with Swift 中文翻译 - 8
- swift NSURLSession 使用方法
- Swift 利用UIScrollView和两个UIImageView实现图片轮滚