在自定义的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];
}
网友评论