成为第一响应者未触发
我有一个视图控制器,其 viewDidLoad 方法在其关联视图中包含的文本字段(电子邮件)上调用成为FirstResponder:
-(void) viewDidLoad {
[email becomeFirstResponder];
}
该视图控制器通过将其推入导航控制器的堆栈来加载。上面的代码第一次运行效果很好。
但是,稍后在应用程序中,当我想返回到此视图控制器时,键盘不会自动出现(这是在使用 popToViewController:animated 时)。相反,用户必须手动将焦点设置到文本字段才能显示键盘...我的猜测是 popToViewController:animated 加载相关视图控制器后不会调用 viewDidLoad ?
我该如何解决这个问题?
I have a view controller whose viewDidLoad method invokes becomeFirstResponder on a textfield (email) contained within its associated view:
-(void) viewDidLoad {
[email becomeFirstResponder];
}
This view controller is loaded by pushing it onto the navigation controller's stack. The above code works great for the first time round.
However, later on in the application when I want to return to this view controller the keyboard doesn't appear automatically (this is when using popToViewController:animated). Instead the user has to manually set the focus to a textfield for the keyboard to appear...My guess is viewDidLoad isn't invoked after popToViewController:animated has loaded the relevant view controller?
How do I resolve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
viewDidLoad
仅在第一次调用。当您希望每次出现视图时都运行某些内容时,请使用 viewWillAppear 。viewDidLoad
is only invoked the first time. UseviewWillAppear
when you want something to run every time a view appears.尝试将其放入 viewWillAppear 中。 viewDidLoad 通常只会运行一次,除非您特别告诉它。
Try putting it in viewWillAppear. viewDidLoad will usually only run once unless you specifically tell it otherwise.