resignFirstResponder on keyboard not working?

Discussion in 'iOS Programming' started by dantastic, Feb 6, 2011.

  1. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #1
    Well, it kindof is.

    I have a add player button that adds a uitableviewcell at the bottom of my uitableview.

    The cell has a text field that I make 'becomeFirstResponder' I then shift the view and the offset so that the tableview covers the top half of the screen and the keyboard the bottom half of the screen.

    This way I can see the textfield I'm typing in to.

    If I type whatever into the text field and press done the keyboard drops down and my view return to normal.

    If I just tap done without typing anything onto the text field the view return to normal but the keyboard doesn't drop.

    Code:
    	...
    	[textField setDelegate:self];
    	textField.returnKeyType = UIReturnKeyDone;
    	[textField addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];			
    	[cell.contentView addSubview:textField];
    	[textField becomeFirstResponder];
    	...
    
    Code:
    - (IBAction)textFieldDone:(id)sender {
    	NSLog(@"I am being called when 'done' is pressed - always!");
    	[self resignFirstResponder];
    }
    
    If I comment out the [textField becomeFirstResponder]; the keyboard is behaving correctly (but I have to select the text field manually) so I suspect that I'm not asking the right component to 'resignFirstResponder' in the case there is no text in the textField.

    What component do I need to 'resignFirstResponder' in this case?

    thanks!
     
  2. cnstoll macrumors 6502

    Joined:
    Aug 29, 2010
    #2
    Try resigning first responder and returning YES in the "textFieldShouldReturn" method.
     
  3. dantastic thread starter macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011

Share This Page