Ios PopViewControllerInitiated:点击UIAlertView时为是,使键盘显示在parentVC中
我试图以编程方式打开ViewController 通过这样做Ios PopViewControllerInitiated:点击UIAlertView时为是,使键盘显示在parentVC中,ios,objective-c,uiviewcontroller,uinavigationcontroller,Ios,Objective C,Uiviewcontroller,Uinavigationcontroller,我试图以编程方式打开ViewController 通过这样做 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { [[self navigationController] popViewControllerAnimated:YES]; } 问题是我在这个VC中有文本字段。如果文本字段处于活动状态且键盘正在显示,并且如果我使用退出键盘的命令显示AlertView
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
[[self navigationController] popViewControllerAnimated:YES];
}
问题是我在这个VC中有文本字段。如果文本字段处于活动状态且键盘正在显示,并且如果我使用退出键盘的命令显示AlertView([[self view]endEditing:YES]或[textField resignFirstResponder]
)。然后调用命令popViewControllerAnimated:YES。当前VC被解除,但在父VC出现后短暂。将有一个键盘显示约1秒钟,然后消失
这种行为很烦人。有没有办法解决这个问题?我注意到通过使用[[self-navigationController]popViewControllerAnimated:NO]
键盘不会出现。但我更喜欢在我的应用程序中加入动画
请帮忙
提前感谢我解决了这个问题,使[[self-navigationController]PopViewController激活:是];呼叫时延迟
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 100 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
[[self navigationController] popViewControllerAnimated:YES];
});
@KongHantrakool的答案有效,但也有不足之处,您可以在-(void)willPresentAlertView:(UIAlertView*)alertView中添加[[self view]endEditing:YES]或[textField resignFirstResponder],这样会更好。您也可以尝试以下代码:
#pragma mark - UIAlertView Delegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self performSelector:@selector(popViewController) withObject:nil afterDelay:0.1];
}
- (void)popViewController {
[self.navigationController popViewControllerAnimated:YES];
}
试试这个,我想它可能对你有帮助
- (void)viewWillAppear:(BOOL)animated
{
[textField resignFirstResponder];
}
我也遇到了这个问题,我发现延迟解决方案根本不起作用
alertView
将记住键盘的状态,因此当alertView关闭时,它将恢复键盘。所以问题就出来了:键盘在我们弹出viewController后大约1秒出现
以下是我的解决方案:
在弹出viewcontroller之前,我们只需要确保键盘的状态是隐藏的
我必须使用这个解决方案以及标记的答案来解决这个问题。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
@property (nonatomic) BOOL keyboardDidShow;
- (void)keyboardDidHide:(NSNotification *)notification {
self.keyboardDidShow = NO;
if (self.needDoBack) {
self.needDoBack = NO;
[self showBackAlertView];
}
}
- (void)keyboardDidShow:(NSNotification *)notification {
self.keyboardDidShow = YES;
}
- (void)back {
if (self.keyboardDidShow) {
self.needDoBack = YES;
[self.view endEditing:YES];
} else {
[self showBackAlertView];
}
}