点击cell上的button如何获取tableView

2016-06-22  本文已影响398人  奋斗的小老鼠

这种方法主要用于工厂cell

- (IBAction)diggCountBut:(UIButton *)sender forEvent:(UIEvent *)event {
    //取到 button所在的cell的indexPath
    NSSet *touches =[event allTouches];
    UITouch *touch =[touches anyObject];
    UITableView *tableView = (UITableView *)[[[[sender superview] superview] superview] superview];
    CGPoint currentTouchPosition = [touch locationInView:tableView];
    NSIndexPath *indexPath= [tableView indexPathForRowAtPoint:currentTouchPosition];
    if (indexPath != nil){
     //利用通知发送到ViewController里面实现先做的事情
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dig" object:sender userInfo:@{@"row":indexPath}];
    }
}

上一篇 下一篇

猜你喜欢

热点阅读