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 possib开发者_如何学JAVAle 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?
This worked with my 3GS in iOS4. Are you sure you properly set the UITextField
delegate?
- (BOOL) textFieldShouldReturn:(UITextField*)textField {
[textField resignFirstResponder];
return YES;
}
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.
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.
精彩评论