【发布时间】:2017-05-04 05:12:39
【问题描述】:
团队,
我有 UITableView,其中有 50 多个单元格。 每个单元格的宽度为 60。
当我最多滚动 20 个单元格时,然后点击任何单元格
它给出了高于单元格值的索引路径值而不是单击单元格值
CellForRowAtIndexPath 内部
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[[cell checkButton] addTarget:self action:@selector(checkButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)checkButtonAction:(id)sender
CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.tableview];
NSIndexPath *indexPath = [self.tableview indexPathForRowAtPoint:touchPoint];
UIButton *button = (UIButton *)sender;
}
如果选择的索引为 21,则索引为 20,保持索引计数从零开始。
在 iOS 10.1 iphone 7 plus 设备中观察到该问题,而不是在模拟器 iPhone 7 plus iOS 10.1 (14B72) 中观察到
调试值 {长度 = 2,路径 = 0 - 14}
NSIndexPath 路径应该是 0 - 15,但它给出的是 0 - 14。
【问题讨论】:
-
尝试在转换点用 ((UIButton*)sender) 替换发件人;
-
如果还是同样的问题,那么用下面的“[sender convertPoint:CGPointZero toView:self.view]”试一次
-
@kiran
checkButtonAction:是你按钮的触摸事件吗? -
转换点?我很震惊。
-
@sanket 还是一样的问题。
标签: ios objective-c uitableview didselectrowatindexpath nsindexpath