Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set focus to UITextField in tableCell

Tags:

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

like image 584
nabiullinas Avatar asked Jan 16 '12 17:01

nabiullinas


1 Answers

change [field resignFirstResponder]; with [field becomeFirstResponder];

resignFirstResponder is used to remove keyboard (focus) from text field

like image 137
Saurabh Avatar answered Oct 04 '22 22:10

Saurabh