在UIButton的点击事件中做处理,以下是两种方法:
方法1:
UITableViewCell * cell = [(UITableViewCell*)[sender superview] superview];
NSIndexPath * indexPath = [self.table indexPathForCell:cell];
DLog(@"cell's row %d",indexPath.row);
方法2:
UIButton * btn = (UIButton*)sender;
CGRect buttonRect = btn.frame;
for (UITableViewCell *cell in [self.table visibleCells]) {
if (CGRectIntersectsRect(buttonRect, cell.frame)) {
//TODO
}
}
本文介绍了在UIButton点击事件中处理逻辑的两种方法。方法一通过获取发送者的superview来找到对应的UITableViewCell,并获取其indexPath。方法二则遍历tableView的所有可见单元格,通过CGRectIntersectsRect检查按钮是否位于某个单元格内。
5825

被折叠的 条评论
为什么被折叠?



