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?

Was it helpful?

Solution

  1. Make your class a delegate of UITextField
  2. Go to the Storyboard file, click on the text field and go to connections inspector
  3. Under outlets, connect the delegate to the View Controller
  4. Run it in simulator. It will work
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top