UIAlerViewController的使用
来源:互联网 发布:mac隐藏的照片 编辑:程序博客网 时间:2024/06/06 13:02
这次使用UIAlerViewController,主要是给弹出的警告上得按钮添加方法。
布局是创建一个RootViewController,在自带的视图上添加或删除;
重点
1.UITextField如果什么都不输入的话,不是nil,而是@“”;
2.对UIAlerViewController添加方法,是通过添加UAlerAction。
UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { _textfield.text = @""; }];
3.需要把当前对象的presentViewController设置为创建的ViewController。
[self presentViewController:alertController animated:YES completion:nil];
#import "RootViewController.h"@interface RootViewController ()@property(nonatomic,retain)UITextField * textfield;@property(nonatomic,retain)UIButton *button;@end@implementation RootViewController-(void)dealloc{ [_textfield release]; [super dealloc];}
- (void)viewDidLoad { [super viewDidLoad]; self.textfield = [[UITextField alloc]initWithFrame:CGRectMake(50, 100, 200, 30)]; _textfield.borderStyle = UITextBorderStyleRoundedRect; _textfield.placeholder = @"请输入内容"; self.button = [UIButton buttonWithType:UIButtonTypeCustom]; _button.frame = CGRectMake(100, 200, 50, 30); _button.backgroundColor = [UIColor grayColor]; [_button setTitle:@"提交" forState:UIControlStateNormal]; [_button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal]; [_button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_textfield]; [self.view addSubview:_button]; // Do any additional setup after loading the view.}
-(void)click:(UIButton *)button{ //如果什么都不输入的话,不是nil,而是@“”; if ([_textfield.text isEqualToString:@"123"]) {#pragma mark------------UIAlerView UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"登陆成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",@"找回密码", nil]; [alertView show]; [alertView release]; }else{#pragma mark-------------UIAlerController UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"登陆失败" preferredStyle:UIAlertControllerStyleAlert]; [self presentViewController:alertController animated:YES completion:nil]; UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { _textfield.text = @""; }]; UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"重新登陆" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { _textfield.text = @""; }]; [alertController addAction:action1]; [alertController addAction:action2]; }}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES];}-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == 1) { _textfield.text = @""; }}
0 0
- UIAlerViewController的使用
- GUID使用的使用
- ${}的使用
- 的使用
- @[],@()的使用
- ->的使用
- +、-、*、/、%的使用
- &&的使用
- %:的使用
- Makefile中使用$$的使用
- Makefile中使用$$的使用
- Red5的使用--使用日志
- prefernce的使用具体使用
- 【工具使用】git 的使用
- 关于使用AsyncTaskLoader的使用
- 使用CABasicAnimation的基本使用
- 使用RocketMQ的客户端使用
- gulp的使用基本使用
- 精通脚本黑客
- 个人常用iOS第三方库以及XCode插件介绍
- c++ 模板函数,类模板,仿函数使用实例代码
- python笔记1
- [Leetcode]Basic Calculator
- UIAlerViewController的使用
- 【springmvc】java web使用ajaxSubmit方法实现Excel文件上传
- C++ 函数返回引用
- Scala学习笔记--数组
- 今日总结
- iOS高效编程秘诀—坚持好的编程习惯
- 《剑指offer》之从上往下打印二叉树
- 编写高质量的代码应从命名开始
- AOJ-351-求最值之差