views:

159

answers:

2

Hi Everybody! 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?

+1  A: 

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

- (BOOL) textFieldShouldReturn:(UITextField*)textField {
[textField resignFirstResponder];
return YES;
}
Charter
i guess you meant UITextFieldDelegate - yes my class is implementing it...
dusker
Nope I really meant did you set your class implementing the UITextFieldDelegate protocol as the delegate for the UiTextField outlet.
Charter
In your answer you've stated TextVIEWDelegate.
dusker
Oops sry for the error.
Charter
The only time I've seen this happen is when the UITextField's delegate property is not set to the File's Owner. Why are you calling [opis resignFirstResponder]? Do you mean `if (textField == opis) [textField resignFirstResponder]`?
chrispix
A: 

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.

Scott