Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

like image 521
Pradeep Reddy Kypa Avatar asked Apr 16 '10 06:04

Pradeep Reddy Kypa


People also ask

How do I open a new view controller?

To create a new view controller, select File->New->File and select a Cocoa Touch Class. Choose whether to create it with Swift or Objective-C and inherit from UIViewController . Don't create it with a xib (a separate Interface Builder file), as you will most likely add it to an existing storyboard.

How can I tell if a keyboard is open or not in Swift?

…or take the easy way: When you enter a textField, it becomes first responder and the keyboard appears. You can check the status of the keyboard with [myTextField isFirstResponder] . If it returns YES , then the the keyboard is active.


1 Answers

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];
}
like image 61
Alex Reynolds Avatar answered Sep 28 '22 14:09

Alex Reynolds