美文网首页
根据添加到tableViewCell的控件获取cell

根据添加到tableViewCell的控件获取cell

作者: doubleJJ | 来源:发表于2016-07-19 17:39 被阅读64次

在自定义的tableViewCell加了一个button,在button的点击函数里

方法一:取出button的父视图

[cell.btn addTarget:selfaction:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];

- (void)clickButton:(UIButton *)btn{

UIView *view = btn.superview;

PersonalCenterCell *cell = (PersonalCenterCell *)view.superview;

}

方法二:

[cell.btn addTarget:selfaction:@selector(clickButton:event:) forControlEvents:UIControlEventTouchUpInside];

- (void)clickButton:(UIButton *)btn {

NSSet *touches = [event allTouches];

UITouch *touch = [touches anyObject];

CGPoint currentTouchPosition = [touch locationInView:self.mainTableView];

NSIndexPath *indexPath= [self.mainTableView indexPathForRowAtPoint:currentTouchPosition];

PersonalCenterCell *cell = [self.mainTableView cellForRowAtIndexPath:indexPath];

}

相关文章

网友评论

      本文标题:根据添加到tableViewCell的控件获取cell

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