关于使用UIAlertView之后pop或者push时键盘闪退问题解决方法

当当前页面有UITextField时使用UIAlertView,在pop或者push时,在新的页面键盘会弹出一下,再收回,这是因为在ios8以后,苹果提倡使用UIAlertController而非UIAlertView,目前解决方法有以下两种

1:在pop和push的时候,延迟几秒再执行,具体多少秒最合适,可以自己试一下,我目前设置的是1秒,当然,要大于0.25秒,因为键盘收回的时间是0.25秒,至少得等键盘收回才返回吧。

2:就是使用判断系统,在iOS8以上使用UIAlertController,具体代码如下所示

 

 

if (SYSTEM_VERSION >= 8.0) {

            UIAlertController *alc = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否要保存" preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

                 [self commitData];

            }];

            [alc addAction:sure];

            UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

                [self.navigationController popViewControllerAnimated:YES];

            }];

            [alc addAction:cancel];

 

            [self presentViewController:alc animated:YES completion:nil];

        }else{

        UIAlertView*al=[[UIAlertView alloc]initWithTitle:@"提示" message:@"是否要保存" delegate:self cancelButtonTitle:@"" otherButtonTitles:@"", nil];

            [al show];

        }

 

建议使用第二种方法

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值