通过 Table 视图触发文本字段 select iOS - Objective C

Triggering textfield via Table View did select iOS - Objective C

在 iOS 应用程序中,我有一个 table 视图,其中有 2 行,其中嵌入了文本字段。

Textfield2 是一个带有 pickerview 输入的文本字段,我使用如下设置:

textField2.inputView = pickerView;

所以事情是,右边的 textField 2 图标只是嵌入在 textfield2.rightview 中的图像,导致图像在点击时不会触发 pickerView 输入。

Did select table 查看方法也没有被触发,因为我将文本字段设置为完全占据单元格。因此,经过一番搜索后,我发现禁用 textField2 用户交互可以触发 didSelect。

textField2.userInteractionEnabled = false;

但是,现在我不知道如何通过 didselect tableview 方法触发对 textField2 pickerView 的输入。我尝试了这行代码,但它不起作用。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"Did select row %d",indexPath.row);
    if(indexPath.row == 1){
        [textField2 becomeFirstResponder];
    }
}

我试图搜索如何手动触发对 textField 的输入,但没有找到任何线索。 先谢谢了! :)

经过一些清醒的调试,我发现

textField2.userInteractionEnabled = false;

导致文本字段无法成为响应者。 因此,使用此标志的一个小解决方法是首先启用它以便编辑文本字段并在我们完成编辑后再次禁用它。像这样:

   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"Did select row %d",indexPath.row);
    if(indexPath.row == 1){

        [textField2.userInteractionEnabled = true;
        [textField2 becomeFirstResponder];
    }
}

- (void)donePicker {
// to enable the did select row again
        [textField2.userInteractionEnabled = true;
}