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

UIAlertView,POP返回键盘闪现

2015-07-29 15:05 447 查看
假如有两个ViewController: A 和 B(使用了UINavigationController), 在B中有一个TextField, 一个Button.(在ARC模式下) 在Button调用的方法中创建一个UIAlertView, 在AlertView的代理方法clickedButtonAtIndex中实现pop到A. 也写了[_textField resignFirstResponder];语句.

在TextField中输入时, 键盘弹出, 在键盘不回收的情况下, pop到A, 过1秒中, A就会闪现键盘(就是B的界面上的键盘), 键盘消失时, 程序会执行B的dealloc方法.

如果把UIAlertView替换成UIAlertController的话, 键盘就会在B中先闪现, 再推到A界面. 如果直接在Button调用的方法内实现pop到A(不使用AlertView), 就不会出现这种情况

原因是因为iOS 8.3,dismiss alert view时系统会尝试恢复之前的keyboard input。

所以你要等键盘完全收起之后再pop或者push。直接dispatch_after个0.25秒再执行pop或者push。至于为什么是0.25秒,因为系统键盘收起的duration就是0.25秒。别问我怎么知道的。

解决方法: -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

if (1 == buttonIndex) {

[self performSelector:@selector(popVC) withObject:nil afterDelay:0.25];

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