ios - 将焦点设置到 tableCell 中的 UITextField

标签 ios events uitableview uitextfield

我正在用 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/

相关文章:

ios - 当 subview 重叠时移动 AVPlayer 字幕

ios - UISearchBar 和 UISearchBarController 之间的区别?

ios - 如何使用tableview删除核心数据中的数据

ios - Storyboard中的自定义 TableView 单元格布局似乎无效

ios - 创建一个新的状态栏

ios - Bootstrap 4 选项卡在 iOS 上无法使用 "data-target"而不是 "href"属性

sql - 是否首选在SQL事件中使用结束时间或持续时间?

forms - 使用表单事件时的 Symfony 表单字段顺序

javascript - 如何防止此 transitionend 事件运行两次/多次?

ios - 没有 reuseIdentifier 的 UITableViewCell