您的位置:首页 > 产品设计 > UI/UE

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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐