g-pod wrote:
I can't get the keyboard to disappear at all, not when tapping outside of the text field, not when tapping the button, and not when tapping "Return/Go/etc." on the bottom right of the keyboard.
It's quite likely that your textField instance var isn't connected to the text field object in IB. You can see what's going on by making the commented changes to textFieldShouldReturn:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
NSLog(@"textField=%@", textField); // <-- log value of textField instance var
// if (theTextField == textField) {// <-- temporarily comment out if condition
[textField resignFirstResponder];
//} // <--
return YES;
}
If the log in your Debugger Console says that textField is (null), open the controller xib file in IB and make sure the textField outlet of the view controller (File's Owner) is connected to the text field in the View editor window. One way to inspect and make the connection is to ctrl-click on the File's Owner icon to bring up the black connections panel. The textField outlet should show up in that panel. If it's not connected, ctrl-click on the connector circle and drag to the text field.
If you don't see a textField outlet in the File's Owner connection panel, make sure the textField instance var is declared as IBOutlet in your view controller class @interface file (e.g. MyViewController.h). Before rebuilding, select Clean All Targets in the Xcode Build menu.
<div class="jive-quote">In Interface Builder, when I look at the text field attributes for that text field, under "Text Input Traits", I have "Return Key" as default.
That selection only affects the label that appears on the keyboard's Return key.
make the button perform the same function as the button, and vanish afterward;
I assume you meant for one of these two buttons to be something else. Maybe the keyboard return key? Anyway if my guess about the textField connection was correct, you'll probably have what you wanted.
or have a button that makes the keyboard simply vanish.
As above, once the textField ivar is connected to the actual text field, the resignFirstResponder message will work whenever it's sent.
If my guess is wrong about the connection, please post the log message produced by the above NSLog() code. Also please post a link to the instructions you're following. There are more than one "Hello World" tutorials, so we'll need to be on the same page to do some more debugging.
- Ray
p.s.: When I started this message I hadn't seen alex.bbd's response. Alex makes a good point. textFieldShouldReturn won't be called unless the controller is designated as the text field's delegate. This point only applies to the action of the Return key, so you still need to check the connection I discussed above. After that however, if clicking outside the text field works, but the keyboard Return doesn't, go back to IB and make sure the text field's delegate outlet is connected to the File's Owner. - R