我正在用 UITextField
动态创建一个 TableView 。
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];
现在我想在用户触摸单元格时将焦点设置在这个文本字段上。我写这个
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath {
UITextField* field = (UITextField *) [tblView viewWithTag: newIndexPath.row];
[field resignFirstResponder];
}
但这行不通
最佳答案
将 [field resignFirstResponder];
更改为 [field becomeFirstResponder];
resignFirstResponder
用于从文本字段中移除键盘(焦点)
关于ios - 将焦点设置到 tableCell 中的 UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8883730/