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

2016-07-19  本文已影响64人  doubleJJ

在自定义的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];

}

上一篇 下一篇

猜你喜欢

热点阅读