views:

47

answers:

1

Hello,

I have problem probably the same like this guy:

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.

A: 

Do you use the proper delegate methods?

tadej5553
can you be more specific? Drag and drop UITextField to any view in IB, and launch app, done button must hide keyboard. loginField is dragged to appDelegate already and loginField.text works already..
holms
Yeah, I know, but the Done button DOEN'T hide the keyboard by default. You have to implement this method: - (BOOL)textFieldShouldReturn:(UITextField *)textField or else nothing happens. Check the documentation for details.
tadej5553
Finally somebody told me in plain english what's wrong thanks man, I'll try that =)
holms
..king hell, after googling for 50min I finally understood my problem. And now in plain english for stupid people like me: 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!
holms