关于使用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];
}
建议使用第二种方法
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];
}
建议使用第二种方法
相关文章推荐
- MUI移动开发框架——微信支付(android部分)
- android-UI组件实例大全(十五)------其他对话框:ProgressDialog,Date/TimePickerDialog
- android-UI组件实例大全(十四)------对话框的父类:AlertDialog
- SoapUI———mock数据工具
- android-UI组件实例大全(十三)------消息提示框:Toast和Notification
- android-UI组件实例大全(十二)------ScrollView滚动视图
- android-UI组件实例大全(十一)------Adapter类Four之Gallery画廊视图
- android-UI组件实例大全(十)------Adapter类Four之Spinner列表选项框
- 为什么要关闭 MySQL Query Cache?
- android-UI组件实例大全(九)------Adapter类Three之GirdView网格视图
- [MySQL FAQ]系列 — 线上环境到底要不要开启query cache
- android-UI组件实例大全(八)------Adapter类Two之Autocompletion自动完成文本框
- android-UI组件实例大全(七)------Adapter类One之ListView
- android-UI组件实例大全(六)------ImageView图像视图
- QueryPerformanceFrequency、QueryPerformanceCounter作用
- android-UI组件实例大全(五)------开关按钮ToggleButton和开关Switch
- android-UI组件实例大全(四)------单选按钮(RadioButton)和复选框(CheckBox)
- android-UI组件实例大全(三)------按钮Button与图片按钮ImageButton
- easyui使用,导入js顺序
- android-UI组件实例大全(二)------EditText编辑框