UIAlertController的一些简单实用方法
2015-12-18 11:41
525 查看
1.UIAlertController类似UIAlertView的最基本的使用方法。。直接上代码
-(void)alertViewcontrol
{
UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"输入有误" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"做点什么吧");
}];
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"做点啥呢");
}];
[alertControl addAction:cancelAction];
[alertControl addAction:confirmAction];
[self presentViewController:alertControl animated:YES completion:nil];
}
-(void)alertViewcontrol1//添加textfield的方法
{
UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"输入点东西吧" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"做点什么吧");
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:alertControl.textFields.firstObject];
}];
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"做点啥呢");
}];
[alertControl addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.text = @"可以在这里使用textfield的一些属性";
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listeningTextField:) name:UITextFieldTextDidChangeNotification object:textField];
}];
[alertControl addAction:cancelAction];
[alertControl addAction:confirmAction];
[self presentViewController:alertControl animated:YES completion:nil];
}
-(void)listeningTextField:(NSNotification *)notionfication//监听弹框上的输入内容的变化
{
UITextField *thisTextField = notionfication.object;
NSLog(@"%@",thisTextField.text);
}
-(void)alertViewcontrol
{
UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"输入有误" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"做点什么吧");
}];
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"做点啥呢");
}];
[alertControl addAction:cancelAction];
[alertControl addAction:confirmAction];
[self presentViewController:alertControl animated:YES completion:nil];
}
-(void)alertViewcontrol1//添加textfield的方法
{
UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"输入点东西吧" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"做点什么吧");
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:alertControl.textFields.firstObject];
}];
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"做点啥呢");
}];
[alertControl addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.text = @"可以在这里使用textfield的一些属性";
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listeningTextField:) name:UITextFieldTextDidChangeNotification object:textField];
}];
[alertControl addAction:cancelAction];
[alertControl addAction:confirmAction];
[self presentViewController:alertControl animated:YES completion:nil];
}
-(void)listeningTextField:(NSNotification *)notionfication//监听弹框上的输入内容的变化
{
UITextField *thisTextField = notionfication.object;
NSLog(@"%@",thisTextField.text);
}
相关文章推荐
- 【转】特殊权限控制之SUID、SGID、Sticky
- PowerBuild利用timing实现同时使用多个定时器
- SQL Server中字符串转化为GUID的标量函数实现
- Duilib界面布局文件XML学习-XML文件简介
- UICollectionView 运用
- processing - MySQL example1-conntction(), query() , next() , getInt(1)
- [转]无需看到你的脸就能认出你——实现Beyond Frontal Faces: Improving Person Recognition Using Multiple Cues
- iOS7/8 UIButton高亮状态延迟问题全解
- Java中parse()和valueOf(),toString()的区别
- SQLiteDatabase query 和 rawQuery 的区别
- IOS UITextField 去除字符串首位空格和换行 设置清除按钮显示模式
- Rescue
- Request&Response编程
- protocol isis issues(续1.3----buffer_size相关)
- Java中String、StringBuilder和StringBuffer的简单区别
- 关于SearchView中onQueryTextSubmit方法执行两次的解决方法
- 用系统的TabBar不让系统渲染图片设置文字背影颜色
- 同步辅助类-DelayQueue队列研究
- 时间戳--UUID
- UITextView 点return 隐藏键盘