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

eliavlevy

macrumors newbie
Original poster
Hey guys,
I have a very simple application with a button and text field.
I want (of course) that when you click done after writing in the text field, the keyboard will go away. I added the following, as suggested in the Apple "First iPhone application" tutorial:

Code:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
	if (theTextField == textField) {
		[textField resignFirstResponder];
	}
    return YES;
}

Although, it still doesn't seem to go away.

By the way, the text field is connected to the delegate, or the whatchamacallit.

Any help, please? Thanks.
 
Hey guys,
I have a very simple application with a button and text field.
I want (of course) that when you click done after writing in the text field, the keyboard will go away. I added the following, as suggested in the Apple "First iPhone application" tutorial:

Code:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
	if (theTextField == textField) {
		[textField resignFirstResponder];
	}
    return YES;
}

Although, it still doesn't seem to go away.

By the way, the text field is connected to the delegate, or the whatchamacallit.

Any help, please? Thanks.

Have you designated your view controller a <UITextFieldDelegate> ?
 
I have the same problem - and I have both of these functions in my code:

Code:
- (void)textFieldDidEndEditing:(UITextField *)theTextField {
	[theTextField resignFirstResponder];
}

- (IBAction) doneButtonOnKeyboardPressed:(id)sender {  
}

And yeah, here is my Controller class definition line - or whatever it's called... 🙂

Code:
@interface WmMobileViewController : UIViewController <UINavigationControllerDelegate,UITextFieldDelegate,UIImagePickerControllerDelegate,MyCLControllerDelegate>

I'm totally baffled as to why the keyboard won't dissapear when they click "Done" with these functions, let alone by default (good one Apple). ;-)

You'd think that the natural behavior would be to hide the keyboard and that they would just leave it to developers to override it if they wanted to.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.