Hi there. I'm ploughing through "Beginning iPhone Development" from Apress and thought I had started to get to grips with the basics. Unfortunately I seem to have been mistaken.
I'm trying to close the keyboard with a UIButton (in addition to the "Done") field. (The idea is to eventually make this into an invisible "background" button allowing the user to close
any keyboard when tapping outside the fields.
I have the following files:
(.h)
Code:
#import <UIKit/UIKit.h>
@interface FunViewViewController : UIViewController {
IBOutlet UITextField *nameField;
IBOutlet UITextField *numberField;
}
@property (nonatomic, retain) UITextField *nameField;
@property (nonatomic, retain) UITextField *numberField;
-(IBAction) textFieldDoneEditing:(id)sender;
-(IBAction) backgroundClick:(id)sender;
@end
(.m)
Code:
#import "FunViewViewController.h"
@implementation FunViewViewController
@synthesize nameField;
@synthesize numberField;
-(IBAction) textFieldDoneEditing:(id)sender
{
[nameField resignFirstResponder];
}
-(IBAction) backgroundClick:(id)sender
{
[nameField resignFirstResponder];
NSLog(@"Here I am");
}
...
@end
Now, the [nameField resignFirstResponder] works fine when it's called in the
textFieldDoneEditing action (which is called directly from the 'Did End On Exit' in the IB.
When calling the [nameField resignFirstResponder] in the
backgroundClick action it simply doesn't work. I know the action itself is called OK as the debugger
does return the "Here I am" string.
It's probably some basic concept that I've missed completely, but that's the life of a newbie. Any help would be highly appreciated! Cheers!