BlackMouse
BlackMouse

Reputation: 4552

Scroll a UITableView inside a tableViewCell

I have a custom cell, and add a viewController as a subview to that cell:

TestViewController *vc = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
[self addSubview:vc.view]; 

The new viewController has a tableView in it. When I try to scroll that tableView, the base tableView, where the custom cell lives, is being scrolled.

How can I solve this?

Thanks in advance

Upvotes: 0

Views: 76

Answers (1)

KDaker
KDaker

Reputation: 5909

I would advice against embedding tableviews however if you really want to do it that way, the solution would probably be to implement the hitTest method on the base tableView :

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

    //here you will need to check if the point lies within any of the 
    //child tableviews and return it .. else return the super method

    if ([self pointInChildTable:point]) {
        return [self childTableForPoint:point];
    }
    return [super hitTest:point withEvent:event];
}

note that pointInChildTable and childTableForPoint should probably be the same method that returns a dictionary with the results. I separated them for explanation only.

Hope this helps.

Upvotes: 2

Related Questions