I am creating a table view with UITextFields dynamically.
l_textField = [[UITextField alloc] initWithFrame:TextFieldFrame];
l_textField.tag = cellRow;
l_textField.delegate = self;
l_textField.font = [UIFont boldSystemFontOfSize:14];
l_textField.textColor = [UIColor blackColor];
[l_textField setEnabled:YES];
[cell.contentView addSubview:l_textField];
And now I want to set focus on this text field when user touch cell. I write this
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath {
UITextField* field = (UITextField *) [tblView viewWithTag: newIndexPath.row];
[field resignFirstResponder];
}
But this doesn’t work
change
[field resignFirstResponder];with[field becomeFirstResponder];resignFirstResponderis used to remove keyboard (focus) from text field