IPhone simulator and DONE key for UITextField

I have a problem, probably the same as this guy :

When you click on a text field after entering data, does the "done" button not work? Is this an iphone simulator problem? Please tell me how to make the "done" button work only with Interface Builder .

Decision:

After searching the Internet in 50 minutes, I finally realized my problem. And now in plain English for stupid people like me:

For example, I now use the file myAppDelegate .. so this should give you an idea of ​​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 

put this in your myAppDelegate.m

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

to make textFieldShouldReturn work, you need to right-click on the text field in IB, then in the "Outlets" drag the "delegate" to the controller where you placed this textFieldShouldReturn method! In this case, drag the delegate onto the myAppDelegate icon.

+4
source share
1 answer

Use the appropriate delegate methods. In particular, we implement the UITextFieldDelegate method:

 - (BOOL)textFieldShouldReturn:(UITextField *)textField 

Also, be sure to connect the controller as a delegate. Either programmatically or by connecting it to Interface Builder.

+4
source

All Articles