views:

761

answers:

2

Hi. I have a custom field that allows the user to enter text in a UITextField. To the left of the UITextField is a UIButton. Something like this:

ENTER YOUR NAME: [name input field]

In the about the UIButton has the text "ENTER YOUR NAME:" and the UITextField is the [name input field].

When the user taps the UITextField, the keyboard is displayed on the device, as expected. However, if the user taps the text for "ENTER YOUR NAME:" nothing happens. This is also expected. I need to tell the UITextField that it should bring up the keyboard and begin editing if the UIButton is pressed.

(I have already thought about making the bounds of the UITextField encompass the UIButton. However, due to the alignment of the text in the UITextField, I can't do things like left or right justification. It must remain as centered text.) Thanks for any assistance you can provide.

+2  A: 

What you can do is tie a method to the UIButton's touchDownInside action (in Interface Builder) that calls becomeFirstResponder on the text field. The text field will then begin editing.

Tim
A: 

Tim, that did the trick. In interface builder, I made the UIButton respond to "Touch Up Inside" and then, I created a method that simply did:

- (IBAction)myUIButtonAction:(id)sender {
[myUITextField becomeFirstResponder];
}

Bingo! Tim, Thanks for the assist. [this site is awesome!]

kspeacock
@kspeacock, no problem - happy to help. If my answer solved your problem, you might consider "accepting" it as the right answer by clicking the green checkbox to the left of my answer. This helps other users who might have the same problem find a quick answer should they come across your question in a search.
Tim