弹出框提示的使用 - 不是很完善

来源:互联网 发布:增值税发票数据分析 编辑:程序博客网 时间:2024/05/25 19:57

ios7/8中的使用

// 1.从底部弹出提示(UIActionSheet已经被ios9弃用)UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"恭喜通关" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"其他", nil];[sheet showInView:self.view];// 2.在屏幕中间弹出提示UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"恭喜" message:@"通关了!!!!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"好的", nil];alert.tag = 10;[alert show];// 3.弹出带输入框的弹框UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"数据展示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];// 设置对话框的类型alert.alertViewStyle = UIAlertViewStylePlainTextInput;// 取得唯一的那个文本框,显示英雄的名称[alert textFieldAtIndex:0].text = hero.name;[alert show];alert.tag = indexPath.row;

注意事项:
1.UIAlertView的tag值大的提示框优先弹出;
2.otherButtonTitles 可以输入多个值,并且都是提示框中的按钮

ios9中的使用

在ios9中使用 UIActionSheet 和 UIAlertView 会弹出警告(不报错可以用但是有警告)

'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a
preferredStyle of UIAlertControllerStyleAlert instead

// 1.弹出普通提示框// 初始化提示框UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"恭喜" message:@"通关了!!!!" preferredStyle:UIAlertControllerStyleAlert];//增加一个‘确定’按钮[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){      //点击提示框按钮后响应的代码}]];// 弹出提示框[self presentViewController:alert animated:true completion:nil];// 2.弹出带文本框的提示框UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据展示" message:nil preferredStyle:UIAlertControllerStyleAlert];// 添加确定按钮[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {    // 1.获取文本框的名称    NSString *name = alert.textFields[0].text;    // 2.更新模型数据    MJHero *hero = self.heros[indexPath.row];    hero.name = name;    // 全部刷新    //[self.tableView reloadData];    // 3.局部刷新    NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row inSection:0];    [self.tableView reloadRowsAtIndexPaths:@[path]  withRowAnimation:UITableViewRowAnimationFade];}]];// 添加取消按钮[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];// 添加文本框[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {     textField.text = hero.name;}];// 在控制器中加载alert控件[self presentViewController:alert animated:true completion:nil];
  1. UIAlertController 的 preferredStyle 参数说明:
    UIAlertControllerStyleActionSheet 为底部弹出提示;
    UIAlertControllerStyleAlert为屏幕中间弹出提示;

  2. UIAlertAction 的 style 参数说明:
    UIAlertActionStyleDefault 为普通按钮
    UIAlertActionStyleCancel 为取消按钮
    UIAlertActionStyleDestructive 为危险操作按钮

0 0
原创粉丝点击