您的位置:首页 > 产品设计 > UI/UE

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

2015-12-04 19:27 726 查看
当当前页面有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];

}

建议使用第二种方法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: