iphone simulator and "DONE" keyboard button for UITextField
I have problem probably the same like this guy:
开发者_JAVA百科When clicking on text field, after entering data, "done" button doesn't work?? Is it iphone simulator issue? Please tell me how to get the "done" button work with Interface Builder only.
Solution:
After googling for 50min I finally understood my problem. And now in plain english for stupid people like me:
I'm for example using myAppDelegate file for now.. so this should give you an idea what to do:
#import <UIKit/UIKit.h>
@class imgurViewController;
@interface imgurAppDelegate : NSObject {
UIWindow *window;
imgurViewController *viewController;
//login window
UIButton *loginButton;
UITextField *loginField;
UITextField *passwordField;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet imgurViewController *viewController;
//login window
@property (nonatomic, retain) IBOutlet UIButton *loginButton;
@property (nonatomic, retain) IBOutlet UITextField *loginField;
@property (nonatomic, retain) IBOutlet UITextField *passwordField;
- (IBAction)doLoginButton;
@end
place this to your myAppDelegate.m
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
to make textFieldShouldReturn work, you need to right click on your text field in IB, then in "Outlets" drag 'delegate' to controller where you placed that textFieldShouldReturn method! In this case drag 'delegate' to myAppDelegate icon.
Use the proper delegate methods. Specifically, implement UITextFieldDelegate
method:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
Also, don't forget to wire up the controller as the delegate. Either programmatically, or by connecting it in Interface Builder.
精彩评论