最近有同学总是在问怎么获取不同cell中得button点击事件,就分享一下我的经验,直接上代码。
{
NSIndexPath *_indexPath;
}
-(void)buttonClicked:(UIButton *)button{
UITableViewCell *cell = (UITableViewCell *)[button superview];//获取cell(通过button父视图获取)
_indexPath = [tableView indexPathForCell:cell];//这样就获取到indexPath了
}
//使用手势的时候同理也可以通过获取父视图来获取indexPath
-(void)TapGesture:(UITapGestureRecognizer *)tap{
UITableViewCell *cell = (UITableViewCell *)[[button superview]superview];
_indexPath = [tableView indexPathForCell:cell];//这样就获取到indexPath了
}