简体   繁体   English

如何在视图已加载时出现键盘打开视图?

[英]How to open the view with the keyboard appearing when the view is already loaded?

I have a requirement where I have a textfield in a view. 我有一个要求,我在视图中有一个文本字段。 When I want to open the view by switching the tab (TabBased Application), first time when the view is loaded the keyboard appears because i loadview method is called. 当我想通过切换选项卡(TabBased Application)打开视图时,第一次加载视图时键盘出现,因为我调用了loadview方法。 But when I switch to tab2 and again switch to tab1 again, load view is not called. 但是当我切换到tab2并再次切换到tab1时,不会调用加载视图。 I want the keyboard to appear every time I open the tab1 page. 我希望每次打开tab1页面时都会出现键盘。

Use -viewWillAppear: in your view controller to send your text field a -becomeFirstResponder message, eg: 使用-viewWillAppear:在视图控制器中发送文本字段-becomeFirstResponder消息,例如:

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [myTextField becomeFirstResponder];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当视图已经显示时如何防止键盘向上移动视图 - How to prevent keyboard from moving the view up when it is already shown 打开键盘时移动视图的问题 - Problem with moving the view when the keyboard is open UIWebview:如果Web视图中任何已加载的链接无法打开,如何通知UIViewController - UIWebview : How to notify UIViewController if any of the already loaded link in the web view fails to open 如果已经显示键盘,如何根据键盘显示/隐藏调整视图大小 - How to resize view according to keyboard show/hide if keyboard is already shown 如何防止键盘显示在自定义警报视图上 - How to prevent the keyboard from appearing over a custom alert view 如何在单击文本字段但不出现键盘的情况下显示模式视图? - How to show a modal view upon a click of a textfield but without the keyboard appearing? 键盘在Web视图中无法正确显示-横向模式 - Keyboard in not appearing correctly in web view - Landscape mode 出现键盘更改视图的框架 - Appearing keyboard changes view's frame 防止加载或显示视图 - Prevent a view from being loaded or appearing Tableview forms 需要让键盘在文本字段位于底部时出现提升视图,但当用户滚动时则不需要,因此它位于顶部 - Tableview forms need to have keyboard appearing raise view when textfield is at the bottom but not when user scrolls so it is at the top
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM