Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 20, 2008, 02:06 PM   #1
bejo
macrumors newbie
 
Join Date: Apr 2008
[iPhone] How to set focus to a specific GUI element?

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 is offline   0 Reply With Quote
Old Apr 20, 2008, 04:13 PM   #2
iphoneGuy
macrumors member
 
Join Date: Oct 2007
Location: [[NSLocation alloc] initWithCity: Chicago]
Quote:
Originally Posted by bejo View Post
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
[myTextField becomeFirstResponder];
iphoneGuy is offline   0 Reply With Quote
Old Apr 20, 2008, 05:43 PM   #3
bejo
Thread Starter
macrumors newbie
 
Join Date: Apr 2008
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)
bejo is offline   0 Reply With Quote
Old Apr 20, 2008, 05:48 PM   #4
iphoneGuy
macrumors member
 
Join Date: Oct 2007
Location: [[NSLocation alloc] initWithCity: Chicago]
Quote:
Originally Posted by bejo View Post
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];
iphoneGuy is offline   0 Reply With Quote
Old Apr 20, 2008, 06:13 PM   #5
bejo
Thread Starter
macrumors newbie
 
Join Date: Apr 2008
Quote:
Originally Posted by iphoneGuy View Post
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)
bejo is offline   0 Reply With Quote
Old Apr 3, 2009, 07:23 PM   #6
TPALTony
macrumors regular
 
Join Date: May 2007
Quote:
Originally Posted by bejo View Post
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.
TPALTony is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
iTunes: How to retain "date added" when moving content from internal to external HDD? jayrio Mac Applications and Mac App Store 11 Mar 22, 2013 05:40 AM
How to supercharge Mini? ranny2 Mac mini 18 Oct 27, 2011 08:53 PM
How To Remove Server Part Of Lion? hhaydenn iMac 2 Aug 18, 2011 05:21 PM
How to set Itunes to allow user to browse for a selected Iphone FW kpham iPhone 1 Jul 28, 2008 05:47 PM
quick iTunes question - how to bring focus to library? ero87 Mac Applications and Mac App Store 2 Feb 12, 2007 06:29 PM


All times are GMT -5. The time now is 12:43 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC