【发布时间】: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