【问题标题】:how to get indexpath uitextfield inside tableviewcell?如何在 tableviewcell 中获取 indexpath uitextfield?
【发布时间】:2015-10-13 17:57:36
【问题描述】:

我只知道像这样在 tableviewcell 中获取 indexpath 按钮

CGPoint center= [发件人中心]; CGPoint rootViewPoint = [[sender superview] convertPoint:center toView:_tableView1]; NSIndexPath *indexPath = [_tableView1 indexPathForRowAtPoint:rootViewPoint]; NSLog(@"%@",indexPath);

但我需要了解 textfield thx 来帮助我!

【问题讨论】:

  • 你到底想在这里实现什么?
  • 我在tableviewcell中有标签(用于问题标签)和文本字段(用于答案文本字段),但我需要在文本字段中输入文本..问题出在我的API应该循环参数ANSWER(这应该在uitextfield),就像 ANSWER1 ANSWER2 ANSWER3 一样,我已经在我的 uitextfield 中声明了参数 ANSWER 但是当我在所有循环的 uitextfield 中插入文本并单击 OK 时,我的参数 ANSWER 仍然为空,因为 uitextfield 不知道哪个是 ANSWER1 或 ANSWER2 或 ANSWER3,它的应该从头到尾连续循环..
  • 我想使用标签,就像我之前成功获取我的按钮的 indexpath 一样,就像这样 self.button.tag=indexPath.row;但我不知道如何使用 uitextfield 获取 indexpath 使用标签

标签: ios objective-c xcode uitextfield


【解决方案1】:

还有另一种获取索引行的方法!

在 cellForRow 中这样做:

textField.tag = indexPath.row;

在 textField 方法中这样做:

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    NSInteger row = textField.tag;    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
} 

【讨论】:

  • 我应该在哪里使用 *indexpath?
  • 问题是如何获取indexPath。您可以选择在哪里使用它:)
【解决方案2】:

要获取包含文本字段的单元格的indexPath,您需要做几件事。

  1. 使viewController类成为tableView单元格中textField的代表
  2. 像这样在viewController 的类中实现textField 的delegateProtocoltextFieldDidBeginEditing 方法

- (void)textFieldDidBeginEditing:(UITextField *)textField { //Here you can you the same logic to find the indexPath of the cell like you use in case of a button. }

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 2019-02-26
    • 2014-07-27
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多