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

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值