【问题标题】:UITableView getting the indexPath in textFieldDidBeginEditing:UITableView 在 textFieldDidBeginEditing 中获取 indexPath:
【发布时间】:2013-07-09 14:32:53
【问题描述】:

我有一个动态的tableView。几个单元格有一个textField

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(15,10,260,40)];
textField.delegate = self;
[cell addSubview:textField];

我正在尝试在textFieldDidBeginEditing 中获取indexPath。这是我的代码

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    CGPoint location = [self.view.superview convertPoint:self.view.center toView:self.orderTableView];
    NSIndexPath *indexPath = [self.orderTableView indexPathForRowAtPoint:location];
    NSLog (@"IndexPath %@", indexPath);
    NSLog (@"IndexPath.ROW %i", indexPath.row);  
}

我有前 4 个单元格(索引 0 - 3)是标准单元格。在前 4 个单元格之后,我可以使用 UITextField 动态拥有多达 3 个自定义单元格。

在 UIViewController 与 UITableView 一起出现后,无论我点击什么带有 UITextField 的 TableViewCell,下面的 NSLog 都会不断向我显示以下内容:

2013-07-09 07:21:40.910 MyApp[2884:c07] IndexPath <NSIndexPath 0xa0a5d60> 2 indexes [0, 3]
2013-07-09 07:21:40.910 Mypp[2884:c07] IndexPath.ROW 3

我怎样才能得到正确的indexPath 单元格UITextField 调用键盘?

【问题讨论】:

    标签: ios uitableview uitextfield nsindexpath


    【解决方案1】:

    我认为你在正确的轨道上。但我相信您所引用的点(视图控制器视图的中心)不会为您提供准确的位置。只要您的文本字段的框架留在单元格内,我相信这应该可以工作。

    //convert the textfield's frame origin in the cell to frame origin in table view
    CGPoint location = [self.tableView convertPoint:textField.frame.origin fromView:textField.superview];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多