Possible Duplicate:
Dismiss keyboard on touch anywhere outside UITextField
MyViewController in interface builder :
In my custom TableViewCell I have a TextField. My plan is disappear KeyPad when User Clicks outside the touchpad.
I could not make it works using UITapGestureRecognizer
in viewDidLoad:
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
[self.tableView addGestureRecognizer:gestureRecognizer];
Then how should I make it work with cell.TextField
?
I read about this solution here:
[self.view endEditing:YES];
or
[[self.tableView superView] endEditing];
I couldn't make it work neither. Where should I use them?
Or if you have any better way, please let me know.
Edit
I could not make it work:
@property (nonatomic, strong) UITextField *cellTextField;
in viewDidLoad:
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
[self.settingTableView addGestureRecognizer:gestureRecognizer];
And we have:
- (void) hideKeyboard {
[self.cellTextField resignFirstResponder];
}
And :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
SettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
self.cellTextField = cell.dataEdit;
What is my fault?