Keyboard does not disappear, even after textFieldShouldReturn

Discussion in 'iOS Programming' started by eliavlevy, Jun 16, 2009.

  1. macrumors newbie

    Feb 8, 2009
    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:

    - (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.
  2. macrumors regular

    Jun 18, 2008
    Have you designated your view controller a <UITextFieldDelegate> ?
  3. macrumors newbie

    Jan 31, 2009
    I have the same problem - and I have both of these functions in my 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... :)

    @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.
  4. macrumors newbie

    Mar 3, 2010
    open the
    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
  5. macrumors demi-god


    Oct 16, 2006
    That is correct or if your doing the interface in code, you can use the line
    self.TEXTFIELDNAME.delegate = self;
  6. macrumors newbie

    Jul 10, 2010
    Thanks Montalat

    Thank you very much that solved it:eek:

Share This Page