I am new to iPhone development.
I have a UITextField, in that when I press enter I need to hide the keyboard.
Any way to accomplish this?
Implement the UITextFieldDelegate
protocol's textFieldShouldReturn:
method, and return YES
based on the object that is passed in.
- (BOOL) textFieldShouldReturn:(UITextField *) textField {
[textField resignFirstResponder];
return (textField == someTextField);
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; }
First if the textfield global object is myTextField then <br>
In .h file <br>
@interface MyScreen : UIViewController <**UITextFieldDelegate**>
{
UITextField *myTextField;
}
@property (nonatomic,retain) IBOutlet UITextField ***myTextField**;<br>
In .xib <br>
Attach myTextField to the control.<br>
In .m File <br>
- (void) viewDidLoad<br>
{
[super viewDidLoad];
myTextField.delegate = self;
}
If you want to return the keyboard on particular return button of keyboard press: <br>
#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
If you want to return on your particular button <br>
- (IBAction) myButtonPressed:(id)sender
{
[self.myTextField resignFirstResponder];
}
Apologise for my bad english.
Thanks & Regards,
Gautam Tiwari
Ios Application Developer
精彩评论