dusker
dusker

Reputation: 580

UITextField resign first responder iOS4

I have a simple piece of code that works on every system except iOS4. It's about resigning first responder for a UITextField. The text field is all wired up, and here's the code for the delegate:

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [opis resignFirstResponder];
    return YES;
}

I've tried it almost every possible way, trying to return NO as well and it doesn't work. The weirdest thing is that it DOES work on every iphone OS before 4.0 and on iPad as well (tested in simulators and on actual devices) Can anyone help?

Upvotes: 3

Views: 8403

Answers (3)

Charter
Charter

Reputation: 783

This worked with my 3GS in iOS4. Are you sure you properly set the UITextField delegate?

- (BOOL) textFieldShouldReturn:(UITextField*)textField {
[textField resignFirstResponder];
return YES;
}

Upvotes: 4

theiOSguy
theiOSguy

Reputation: 608

This is a very classic problem. I assume you are setting the delegate to your textField but the question is where? Are you setting in the initWithNib... initializer of your controller? Than that is wrong. Because your text field is not initialized by then. Its initialize in viewDidLoad method, so you should set your delegate there and it should work.

Upvotes: 0

scott4arrows
scott4arrows

Reputation: 80

Not sure if this is similar to your case, but I have a UITextField in a UIAlertView and HAD a similar problem with keyboard not dismissing on resignFirstResponder.

Here was my solution:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    [alert resignFirstResponder];
    return YES;
}

It seems that the alert became firstResponder after textfield resigned.

Upvotes: 1

Related Questions