- Make your class a delegate of UITextField
- Go to the Storyboard file, click on the text field and go to connections inspector
- Under outlets, connect the delegate to the View Controller
- Run it in simulator. It will work
iOS) HIding Keyboard in a cell in UITableView
-
17-01-2022 - |
Question
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"searchCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
searchField = (UITextField *)[cell viewWithTag:10000];
[searchField resignFirstResponder];
}
Okay, I have a cell with a identifier name of "searchCell". This cell contains one single UITextField with tag 10000 that pops up a keyboard on the bottom of the screen. When a user touches another cell, the keyboard must be hidden so that the user can have larger space to scroll up and down.
However, when a keyboard has popped up and a user touches(select) a cell, the code above is called but not working... :( It seems like the assigned UITableViewCell is not the one that the user is currently using. What am I doing wrong here?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow