当视图已经加载时,如何在出现键盘的情况下打开视图?

问题描述:

我需要在视图中有文本框的地方.当我想通过切换选项卡(基于Tab的应用程序)打开视图时,第一次加载视图时会出现键盘,因为调用了loadview方法.但是,当我切换到tab2并再次切换到tab1时,不会调用加载视图.我希望每次打开tab1页面时都出现键盘.

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. But when I switch to tab2 and again switch to tab1 again, load view is not called. I want the keyboard to appear every time I open the tab1 page.

在视图控制器中使用 -viewWillAppear:向您的文本字段发送 -becomeFirstResponder 消息,例如:

Use -viewWillAppear: in your view controller to send your text field a -becomeFirstResponder message, e.g.:

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