对话框
2015-12-14 11:44
393 查看
对话框 UIAlertView在8.0之后就被UIAlertController替换了
8.0之后有代替的控件
#pragma mark - 加载视图 - (void)viewDidLoad { [super viewDidLoad]; //初始化两个按钮 self.btnShow = [UIButton buttonWithType:UIButtonTypeRoundedRect]; self.btnShow.frame = CGRectMake(20, 100, 100, 50); //设置标题 [self.btnShow setTitle:@"start" forState:UIControlStateNormal]; //添加开启事件方法 [self.btnShow addTarget:self action:@selector(shows:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:self.btnShow]; } #pragma mark - UIAlertViewDelegate - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ //获得当前索引按钮的标题 NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; NSLog(@"%@",title); } #pragma mark - show -(IBAction)shows:(id)sender{ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"My Title" message:@"show to you" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",@"Other", nil]; [alert show]; }
8.0之后有代替的控件
#pragma mark - show -(IBAction)shows:(id)sender{ // UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"My Title" message:@"show to you" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",@"Other", nil]; // [alert show]; UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil //nil 这一项就会隐藏 message:@"This is an alert." //nil 这一项就会隐藏 preferredStyle:UIAlertControllerStyleAlert]; // typedef enum UIAlertControllerStyle: NSInteger { // UIAlertControllerStyleActionSheet = 0, //底端出现的 就是 UiActionSheet // UIAlertControllerStyleAlert //对话框 // } UIAlertControllerStyle; UIAlertAction* OKAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { NSLog(@"%@",action.title); }]; UIAlertAction* CancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { NSLog(@"%@",action.title); }]; //addAction 添加 [alert addAction:OKAction]; [alert addAction:CancelAction]; [self presentViewController:alert animated:YES completion:nil]; }
相关文章推荐
- mysql缓冲和缓存设置
- 转载-java多线程与并发面试题
- 广告点击率的贝叶斯平滑
- params(C# 参考)
- windows窗口程序输出printf打印信息
- JDBC批处理数据
- WebService:WSDL、@Webservice、@WebMethod、@WebResult、@WebParam、
- 4.mysql数据库创建,表中创建模具模板脚本,mysql_SQL99标准连接查询(恩,外部连接,全外连接,交叉连接)
- Jquery千位分隔符+保留N为小数
- 显示连接服务器后的所有数据库 mysql_fetch_array()
- JAVA数据库连接池实现
- mantis 项目bug跟踪器
- Activity的生命周期
- Tomcat 性能优化
- 10020---JavaScript--函数
- Ubuntu无法挂载NTFS硬盘或移动硬盘的问题
- Java网络编程(五)socket的半包,粘包与分包的问题
- Android存储子系统流程--vold
- java web 下载urlconnection
- plsql deveploper安装