ios uitableview button 获取cell indexpath.row
2016-08-05 18:12
239 查看
在iOS7下面已经无效,因为iOS7的层级关系发生变化
UITableViewCell->UITableViewCellScrollView->UITableViewCellContentView->Your custom view
下面有2种方法解决这个问题
-(void) visitButtonClicked:(UIButton *)sender
{
// 第一种,兼容所有的版本
UIView *superView = sender.superview;
UITableViewCell *foundSuperView = nil;
while (nil != superView && nil == foundSuperView) {
if ([superView isKindOfClass:[UITableViewCell class]]) {
foundSuperView = (UITableViewCell *)superView;
} else {
superView = superView.superview;
}
}
NSLog(@"founda = %d", [_tableView indexPathForCell:foundSuperView].row);
}
// 第2种,不兼容iOS7以下
UITableViewCell *cell = (UITableViewCell *)[[[sender superview] superview] superview];
NSLog(@"foundb = %d", [_tableView indexPathForCell:cell].row);
}
UITableViewCell->UITableViewCellScrollView->UITableViewCellContentView->Your custom view
下面有2种方法解决这个问题
-(void) visitButtonClicked:(UIButton *)sender
{
// 第一种,兼容所有的版本
UIView *superView = sender.superview;
UITableViewCell *foundSuperView = nil;
while (nil != superView && nil == foundSuperView) {
if ([superView isKindOfClass:[UITableViewCell class]]) {
foundSuperView = (UITableViewCell *)superView;
} else {
superView = superView.superview;
}
}
NSLog(@"founda = %d", [_tableView indexPathForCell:foundSuperView].row);
}
// 第2种,不兼容iOS7以下
UITableViewCell *cell = (UITableViewCell *)[[[sender superview] superview] superview];
NSLog(@"foundb = %d", [_tableView indexPathForCell:cell].row);
}
相关文章推荐
- UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题)
- UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题
- iOS UITableView之cellForRowAtIndexPath和indexpathForCell分别获取指定cell和indexpath
- iOS UITableView之cellForRowAtIndexPath和indexpathForCell分别获取指定cell和indexpath
- iOS TableView didSelectRowAtIndexPath选中某Cell后获取其Cell实例对象
- iOS中获取用户所点击的位置信息,并通过这个位置信息得到tableView的中的cell的indexPath.section
- iOS 运行出现:Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /Sourc
- Uitableview中didSelectRowAtIndexPath常用的获取cell信息的方法
- iOS中如何通过点击UITableViewCell中的Button来获取当前Cell的indexPath
- 获取UItableView中button所在的section和row
- iOS TableView didSelectRowAtIndexPath选中某Cell后获取其Cell实例对象
- iOS中UITableView的cell点击事件不触发didSelectRowAtIndexPath
- iOS中UITableView的cell点击事件不触发didSelectRowAtIndexPath
- iOS TableView didSelectRowAtIndexPath选中某Cell后获取其Cell实例对象
- 通过点击cell上的Button获取tableView的indexPath
- UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题)
- Ios 该图显示其出现的相关问题定义UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
- TableView的cell上面加button,实现点击button可以获取到cell的行号或者indexPath
- ios tableview didSelectRowAtIndexPath方法中,获取某个cell的实例
- ios UITableView 获取点击cell对象