Friday, 26 October 2012

Hide keyboard programmatically in iOS

1. Add the following code to the implementation file (.m)

-(void) textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
}

And in the header file (.h)
-(void)textFieldShouldReturn:(UITextField *)textField

2. Add target to the textField:
txtField.delegate = self;
[txtField addTarget:self action:@selector(textFieldShouldReturn:)
          forControlEvents:UIControlEventTouchCancel];

That's it! Test it out. Hope you find this useful. 



No comments:

Post a Comment