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

eliavlevy

macrumors newbie
Original poster
Feb 8, 2009
12
0
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.
 

ghayenga

macrumors regular
Jun 18, 2008
190
0
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> ?
 

funnylookinhat

macrumors newbie
Jan 31, 2009
4
0
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.
 

KoolStar

macrumors demi-god
Oct 16, 2006
825
9
Kentucky
open the
MyViewController.xib
click on the TextField
open the Connections Inspector or do :Tools , Connections Inspector
slide the delegate button to File's Owner in the MyViexController .xib window
That s all save all and it work
Be well
http://images.macrumors.com/vb/images/smilies/smile.gif

That is correct or if your doing the interface in code, you can use the line
Code:
self.TEXTFIELDNAME.delegate = self;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.