Keyboard Won't Dismiss

Discussion in 'iOS Programming' started by newtoiphonesdk, Apr 12, 2012.

  1. newtoiphonesdk macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    RemindMeViewController.h

    Code:
    
    @interface RemindMeViewController : UIViewController  {
    
    	UITextField *reminderText;
    
    }
    @property (nonatomic,retain) IBOutlet UITextField *reminderText;
    
    RemindMeViewController.m

    Code:
    @implementation RemindMeViewController
    
    @synthesize reminderText;
    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
    	
    	[reminderText resignFirstResponder];
    	return YES;
    }
    
    I then open .xib and set delegate of ViewController to the UITextField, and set the Outlet for the UITextField to reminderText. When I click Done on the keyboard, nothing happens. What's going on here?
     
  2. cMacSW macrumors regular

    Joined:
    Mar 20, 2006
    #2
    I think this should be the other way around, set the delegate of the UITextField to the ViewController.

    Setting a breakpoint in this method should tell you if it's hooked up right.
     
  3. HannKett macrumors member

    Joined:
    Feb 25, 2012
    Location:
    Europe
    #3
    You can set a transparent button across the view that will send it back down again with resignFirstResponder
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    That is not that neatly solved then..
    Best way is to use delegates, or check a touch outside the keyboard to dismiss the keyboards.
     
  5. HannKett macrumors member

    Joined:
    Feb 25, 2012
    Location:
    Europe
    #5
    Do you have an example to check for touch outside of keyboard?

    I learned it the untidy way and have stuck with it, but I think everyone aims for tidier code =)
     
  6. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    Sure ^_-

    Code:
    - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {} 
    
    If you do your resign here it should work fine :)
     
  7. HannKett macrumors member

    Joined:
    Feb 25, 2012
    Location:
    Europe
    #7
    Interesting, thanks man will try it tonight
     

Share This Page