Keyboard does not disappear, even after textFieldShouldReturn

Discussion in 'iPhone/iPad Programming' started by eliavlevy, Jun 16, 2009.

  1. macrumors newbie

    Joined:
    Feb 8, 2009
    #1
    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.
     
  2. macrumors regular

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

    Joined:
    Jan 31, 2009
    #3
    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.
     
  4. macrumors newbie

    Joined:
    Mar 3, 2010
    #4
    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
     
  5. macrumors demi-god

    KoolStar

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

    Joined:
    Jul 10, 2010
    #6
    Thanks Montalat

    Thank you very much that solved it:eek:
     

Share This Page