4

I have a UIPickerView in the footer of a table (from which I plan to issue "pagination"-style requests for the table--the picker will list the pages available of the LARGE data set I'm navigating, and let the user jump straight to any "page" of the data).

My picker receives taps; if I tap on a row of the picker that isn't the selected one, it rolls into the center space of the picker. But if I drag my finger on the picker, I scroll the TABLE, not the picker contents.

I tried installing a UIView subclass in my tableFooterView to see if I could catch touches, and I can... but not touches on the picker. Touches AROUND the picker do in fact fire that UIView subclass's -touchesBegan. But not ones on the picker itself.

1 Answer 1

8

Here's what ended up working.

I made my table into a subclass of UITableView (called PickerSensitiveUITableView).

The I implemented this method:

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView* result = [super hitTest:point withEvent:event];

    if ([result.superview isKindOfClass:[UIPickerView class]])
    {
          self.scrollEnabled = NO;
    }
    else 
    {
          self.scrollEnabled = YES;    
    }
    return result;
}

So now when the touch happens inside the bounds of the picker (actually ANY picker in the table!) it turns off the scrollability of the UITableView.

It occurs to me a more general solution would be to do this as a category on UIScrollView. The problem isn't with tables so much as with the UIScrollView that UITableView is a subclass of...

2
  • the thing with categories is that method overriding is not guaranteed.
    – Pacu
    Feb 11, 2011 at 7:20
  • 1
    Awesome solution, clever and simple. Allowed me to enable swipe to delete in a tableview located in an horizontal scrollview. Thanks a lot.
    – Jukurrpa
    Nov 15, 2012 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.