当 UITextField 在 modalView 中有第一响应者时,UINavigationController 堆栈错误

Posted

技术标签:

【中文标题】当 UITextField 在 modalView 中有第一响应者时,UINavigationController 堆栈错误【英文标题】:UINavigationController stack error when UITextField has first responder in modalView 【发布时间】:2011-10-10 15:35:44 【问题描述】:

我在 UIViewController 中有一个 UITextField,它被推送到 UINavigationController 堆栈中。 UINavigationController 显示为 modalViewController。

如果文本字段在点击后退按钮时处于第一响应者状态(即键盘已启动),则视图会按应有的方式弹出,但它会导致堆栈中的每个其他视图控制器出现导航栏错误:“后退”按钮导航栏上的文本颜色错误且没有背景图片,标题消失,点击其他自定义导航栏按钮无效。

我已尝试在 viewWillDisappear: 和 viewDidDisappear: 中退出文本字段的第一响应者状态。

【问题讨论】:

我很好奇,这是否只发生在模拟器中但在设备上有效? @chown 它发生在模拟器和设备上。 啊,那我的建议不适用,抱歉=/。 【参考方案1】:

改用以下方法

在 viewController 中,而不是将 modalViewController '推'到 NavigationController 上,只需调用

[self presentModalViewController:self.myModalViewController animated:YES];

然后,当您想摆脱它时(例如,在视图左上角的按钮中)在 MyModalViewController 中有一个称为例如的操作

- (IBAction)doneAction 
    [self dismissModalViewControllerAnimated:YES];

【讨论】:

对不起,我应该澄清一下:viewController 没有作为模态视图控制器推送到导航控制器上。 UINavigationController 被呈现为 modalViewController,并且 viewController 被推送到导航控制器上。

以上是关于当 UITextField 在 modalView 中有第一响应者时,UINavigationController 堆栈错误的主要内容,如果未能解决你的问题,请参考以下文章

modalview 关闭后 TableView 未重新加载

iPhone:如何使用modalView实现类似于popToRootViewController的功能?

从 ModalView 打开 ModalView

在 ModalView 中丢失 firstResponder

Dismiss ModalView 在这里不起作用

应用程序委托中的 TabBased 应用程序 + modalview