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 everytime i open the tab1 page.. Please Help Me.
+1
A:
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];
}
Alex Reynolds
2010-04-16 06:51:34
I have done the same thing... But ViewWillAppear method is not called everytime......Here is the Code- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [searchForProduct becomeFirstResponder];}Please Help
Pradeep Reddy Kypa
2010-04-16 07:01:18
You code should work, assuming all the objects are instantiated and wired up. Try adding an `NSLog` statement to verify that `-viewWillAppear:` gets called. Also make sure `searchForProduct` isn't `nil` and/or that it is hooked up properly if you're using Interface Builder for your view.
Alex Reynolds
2010-04-16 07:34:49
searchForProduct is not released.. It contains the memory allocation... The Problem is viewWillAppear Method is never called...
Pradeep Reddy Kypa
2010-04-16 07:45:04
What class are you putting `-viewWillAppear:` into? Are you putting it into a `UIViewController` subclass or a `UIView` subclass or some other subclass?
Alex Reynolds
2010-04-16 07:57:20
I am putting it in the UIViewController Class
Pradeep Reddy Kypa
2010-04-20 10:10:26
If you're putting it into a view controller, then it should get called. Put an `NSLog` statement in the `-viewWillAppear:` method and watch the Console. If you're not getting a log statement printed to the Console, then something else is wrong with your application unrelated to this.
Alex Reynolds
2010-04-20 16:15:28