Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bejo

macrumors newbie
Original poster
Apr 20, 2008
9
0
I'd like to set focus to a UITextField control (enforce editing mode) just after loading a window (view). Is it possible? I've done some google and apple's doc searching but with no luck :(
 

bejo

macrumors newbie
Original poster
Apr 20, 2008
9
0
Thank you for a quick answer. My text field gets focus, however the screen keyboard doesn't apear :(. I also tried overriding the following method in my view controller, with no success:
Code:
- (void)viewWillAppear:(BOOL)animated {
	[fldKeyword becomeFirstResponder];
}
(fldKeyword outlet is of course properly connected to the UI element)
 

iphoneGuy

macrumors member
Thank you for a quick answer. My text field gets focus, however the screen keyboard doesn't apear :(. I also tried overriding the following method in my view controller, with no success:
Code:
- (void)viewWillAppear:(BOOL)animated {
	[fldKeyword becomeFirstResponder];
}
(fldKeyword outlet is of course properly connected to the UI element)

This is what I do in my loadView(). Works perfect...
Code:
	[fldKeyword becomeFirstResponder];
	[self.view addSubview:fldKeyword];
 

bejo

macrumors newbie
Original poster
Apr 20, 2008
9
0
This is what I do in my loadView(). Works perfect...
Code:
	[fldKeyword becomeFirstResponder];
	[self.view addSubview:fldKeyword];
I assume that loadView() is an overridden method of your View that you created programatically. Is it possible to do the same trick with the Interface Builder, where the UIView class and its instance is created by IB, not programatically? (and only the view controller is available for me from Xcode)
 

TPALTony

macrumors regular
May 29, 2007
145
131
I assume that loadView() is an overridden method of your View that you created programatically. Is it possible to do the same trick with the Interface Builder, where the UIView class and its instance is created by IB, not programatically? (and only the view controller is available for me from Xcode)

I don't believe so, but there's a simple enough workaround...

Declare a property in your View controller as an IBOutlet

IBOutlet UITextField *myFirstFocusField;

In Interface builder, drag an association from the text field you want to have the first focus, to Files Owner and associate with "myFirstFocusField"

That will give you the association you want, so you can use the line of code [myFirstFocusField becomeFirstResponder]; in your viewDidLoad method.

You don't need to do the addsubview line as that's all taken care of.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.