【问题标题】:How I will get the active textfield in Tableview with cell?如何使用单元格获取 Tableview 中的活动文本字段?
【发布时间】:2018-01-12 07:06:18
【问题描述】:

我有一个表格视图单元格。在那我有一个文本字段。当我从选择器视图中选择一个值时,它会出现在每个文本字段中。我将如何在带有单元格的 Tableview 中获取活动的文本字段。我试过了:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    CustomCell *currentCell = (CustomCell *) textField.superview.superview;
    NSIndexPath *currentIndexPath = [self.tableView indexPathForRowAtPoint:currentCell.center];
    NSLog(@"%@",currentIndexPath);
}

【问题讨论】:

  • cellForRowAtIndexPath分享您的代码
  • 代替indexPathForRowAtPoint,您可以使用标签来索引路径并使用cellForRowAtIndexPath 获取该特定单元格并仅重新加载该特定行reloadrowsatindexpaths
  • 你在使用动态uitableviewcell吗?
  • 这个委托方法是在单元格中还是在视图控制器中?

标签: ios objective-c uitableview textfield


【解决方案1】:

在 awakeFromNib 的 Cell 类或 RowatIndexPath 方法的单元格中写入 textField.delegate = self。这样在单元类中你就实现了 textField 委托方法。然后你会得到特定的选定文本字段。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-08
    • 2023-04-07
    相关资源
    最近更新 更多