iOS:AlerView、ActionSheet和AlertController的简单使用
来源:互联网 发布:弹幕网站源码 编辑:程序博客网 时间:2024/05/06 21:03
AlertView的使用:
AlerView的样式:
//alertView代理方法 监听确定按钮的点击- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == 1) { MCHeroModel *model = self.heroArr[alertView.tag]; model.name = [alertView textFieldAtIndex:0].text; [self.tableView reloadData]; }}
同时AlertView还有代理方法可以监听按钮的点击
//点击cell显示alertView- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //创建alertView对象 UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"修改" message:@"修改名称" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; //alerView的样式 有没有文本框、单独一个文本框、单独一个密码输入框和账号密码两个输入框的几种样式 alertView.alertViewStyle = UIAlertViewStylePlainTextInput; //拿到文本框并对其赋值 [alertView textFieldAtIndex:0].text = [self.heroArr[indexPath.row] name]; //显示 [alertView show]; alertView.tag = indexPath.row;}
ActionSheet的使用:
ActionSheet样式:
//点击cell显示actionSheet- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //创建actionSheet对象 UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"修改" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil]; //actionSheet样式 sheet.actionSheetStyle = UIActionSheetStyleDefault; //显示 [sheet showInView:self.view]; sheet.delegate = self;}actionSheet也有代理方法:
//actionSheet代理方法- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == 0) { NSLog(@"点击确定"); }}
AlertController的使用:
AlertView在iOS9.0过期,ActionSheet在iOS8.3也已经过期.
AlertController兼具两者的功能,是AlertView和ActionSheet的代替品.
AlertController没有代理方法,取而代之的是回调.
//点击cell显示alertController- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //创建AlertController对象 preferredStyle可以设置是AlertView样式或者ActionSheet样式 UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"修改" message:@"修改信息" preferredStyle:UIAlertControllerStyleAlert]; //创建取消按钮 UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; //创建确定按钮 UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { MCHeroModel *model = self.heroArr[indexPath.row]; model.name = alertC.textFields[0].text; [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; }]; //添加文本框 [alertC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.text = [self.heroArr[indexPath.row] name]; }]; //添加按钮 [alertC addAction:action1]; [alertC addAction:action2]; //显示 [self presentViewController:alertC animated:YES completion:nil];}
0 0
- iOS:AlerView、ActionSheet和AlertController的简单使用
- iOS alertController之actionsheet样式添加控件(类似自定义actionsheet)
- Actionsheet和AlertView的使用
- IOS 开发学习32 actionSheet的使用
- alertController和UIAlertView 使用示例
- AlertController工具类的封装,让AlertController变得更简单
- [ios]自定义的ActionSheet
- UIAlertController之ActionSheet的使用
- ActionSheet和AlertView的封装
- ActionSheet 使用
- actionsheet使用
- 仿qq弹出列表的actionSheet用oc ,swift2和安卓的简单实现
- iOS开发——ActionSheet的使用与弹出选择对话框
- alertController
- AlertController
- ActionSheet样式UIAlertController的正确使用
- ios8 下面的alert和actionsheet
- IOS8之后ActionSheet和ActionView合体,简单更好用
- Logback学习
- JZOJ 4694 火神的鱼
- CSU 1810 Reverse(贡献)
- DB2数据库 Java应用开发快速入门实例
- phpstorm 2016.2.1最新版本在线激活方法
- iOS:AlerView、ActionSheet和AlertController的简单使用
- 用su切换,输入密码提示认证失败
- 此生,做个有趣的人
- 机器学习第二课:概率与统计的部分说明
- UVA 11426 GCD - Extreme (II)
- Leetcode 338.Counting Bits
- 混合颜料
- |Tyvj|动态规划|1023 奶牛的锻炼
- 容斥原理