views:

56

answers:

1

I have a UIViewController that is a UITextFieldDelegate, and I would like the keyboard for its text field to appear as soon as the user navigates to this view, without having to actually touch the text field. It would also be nice to be able to "dismiss" the entire view when the keyboard is dismissed. I am loading the view from a xib file.

I don't have an ivar in the code for the UITextField as yet. I would guess I need one. At this point I am just relying on the delegate to pop up the keyboard.

(I know its not a UITextViewDelegate, like the tag says, but I am new to stackoverflow and can't create the correct UITextFieldDelegate tag.)

A: 

Sounds like you want to use [textField becomeFirstResponder] in viewDidAppear.

JoeGaggler
That makes sense. But how do I get that textField to begin with? It does not seem to be a property of my view, and although I have added a UITextField ivar to my view, I don't see how to hook it to the textfield in the xib. My class looks kind of like this:@interface NewSceneViewController : UIViewController <UITextFieldDelegate> { IBOutlet UITextField *tField;}@property (nonatomic, retain) UITextField *tField;@end
Paul
Wait, I got it. I needed to add the UITextField ivar and make it a property, then assign it during its @synthesize step (@synethesize textField = tField;), then in IB I needed to attach the new referencing item (tField) to the File's Owner.
Paul
Oh, and I had to make sure (in IB) that the File's Owner was the delegate of both the view and the textfield. Otherwise the keyboard would not respond to the "Done" button.
Paul