美文网首页iOS高阶UI相关iOS开发iOS开发资料收集区
iOS tableView点击cell上的button确定ce

iOS tableView点击cell上的button确定ce

作者: 为之则易ing | 来源:发表于2016-06-02 16:22 被阅读924次

问题描述:当UITableView上面放了一个button,当点击这个button触发事件,需要确定点击的是哪个cell,以此确定该cell的indexPath解决:直接上代码

 UITableViewCell *cell = [btn findSuperViewWithSuperViewClass:NSClassFromString(@"UITableViewCell")]; NSIndexPath *indexPath = [_tableView indexPathForCell:cell];
-(id)findSuperViewWithSuperViewClass:(Class)cla{//UIView的类扩展 
  if (self == nil) {
     return nil;
   } else if (self.superview == nil) {
     return nil; 
  } else if ([self.superview isKindOfClass:cla]) {
   return self.superview; 
  } else { 
  return [self.superview findSuperViewWithSuperViewClass:cla]; 
  }
}

最近发现另外一种方法,同样直接上代码:

CGPoint point = btn.center; 
 point = [table convertPoint:point fromView:btn.superview];
  NSIndexPath* indexpath = [table indexPathForRowAtPoint:point];

相关文章

网友评论

  • ac2c5e86bd8c:iOS tableView点击cell上的button确定cell的indexPath mark
    为之则易ing:@fantasticiOS 需求不同,我的需求就是通过button确定indexPath
    25282f9e7081:如果是点击cell上的button,直接代理或者block反向把值带回控制器就行了,这样搞,人家接手你项目的肯定要骂你

本文标题: iOS tableView点击cell上的button确定ce

本文链接:https://www.haomeiwen.com/subject/lidkdttx.html