8

I have a UIScrollView (with paging) to which I add three UIViews. Each of these UIViews has a UITableView inside. So, the user should be able to scroll horizontally to the page he wants and then scroll vertically in the corresponding table.

However, some of the tables don't receive the scrolling gestures. Usually the first one does behave good, but the other ones do not. I can't select cells nor scroll the table up or down.

I used the default settings for the UIScrollView, except for these ones defined in the viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Load the view controllers
    [self loadViewControllers];

    //Configure the scroll view
    self.scrollView.pagingEnabled = YES;
    self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.scrollView.frame) * viewControllers.count, CGRectGetHeight(self.scrollView.frame));
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.scrollsToTop = NO;
    self.scrollView.delegate = self;

    //Configure the page control
    self.pageControl.numberOfPages = viewControllers.count;
    self.pageControl.currentPage = 0;
}

I can't figure out why I can't scroll some of the tables... Any help would be greatly appreciated.

Thanks in advance!

Sagito
  • 1,036
  • 1
  • 12
  • 31

4 Answers4

4

Try to set

self.scrollView.delaysContentTouches = YES;
self.scrollView.canCancelContentTouches = NO;

Maybe the UIScrollView don't pass touch informations to the subviews.

  • I tried that solution through the interface builder but didn't work. Should I do that in code or is it the same? – Sagito Jul 31 '13 at 15:20
4

I tried to reproduce a simplified version of your needs using basically Interface Builder and it seems to me it's working using basic coding and using default settings. Can you pls check my quick n dirty Github repo and kindly ask to reply whether it is applicable to your situation or what is missing.

https://github.com/codedad/SO_ScrollView_with_Tables

By default Interface Builder creates UIScrollView and UITableViews enabling:

  • Delays Content Touches ON
  • Cancellable Content Touches ON
nzs
  • 3,252
  • 17
  • 22
  • I did not use in my example separate view controllers for all the tables since one view controller acting as datasource for all tables is enough as you can use the 'tableView' parameter both in cellForRowAtIndexPath and numberOfRowsInSection to distinguish the various tables. – nzs Jul 31 '13 at 15:56
  • Well, it seems that both you and @hw731 were correct because in your example and in the link posted by hw371 the difference was in the UITableView size. My tables were a couple of pixels too big whereas in your example they fit correctly and that seemed to be the problem with my code. :-) Thank you so much! – Sagito Jul 31 '13 at 16:30
  • You're welcome! ;) Always hoping concrete working code helps more to others. If you could upvote this answer this might indicate others to check example too. Thx! – nzs Jul 31 '13 at 19:14
  • Sure thing! Just too bad that I can't mark both as the selected answers. ;) – Sagito Jul 31 '13 at 19:18
  • Could you by any chance do this using storyboards? Ive been trying for 3 days know cant find a tutorial for it also. Would appreciate it alot! – Timo Cengiz Apr 14 '15 at 20:43
2

Things I would check:

  1. Check your View Hierarchies - Is something being laid on top of your UITableView, causing it not to receive a tap?
  2. Are your UITableViews being disabled anywhere? I would set a breakpoint in tableView:didSelectRowAtIndexPath: and see if that method is being called.
  3. Check this post

I guess those aren't sure-fire answers but hopefully they'll help discover the problem!

Community
  • 1
  • 1
hgwhittle
  • 9,316
  • 6
  • 48
  • 60
  • Hmm, I don't have any other views. The hierarchy is currently something like this: UIView - UIScrollView --- UIView ----- UITableView However, you are quite right... tableView:didSelectRowAtIndexPath is not called during the "attempted" scroll. But I'm not disabling it (intentionally at least). Any idea why it would become disabled? – Sagito Jul 31 '13 at 15:24
  • Are any delegate/datasource methods being called for your UITableViews? – hgwhittle Jul 31 '13 at 15:37
  • 1
    Yes, I have a UIViewController for each UITableView which is both delegate and datasource of the tables. – Sagito Jul 31 '13 at 15:39
  • I stumbled upon that answer a while ago, but actually I didn't remember to check if the UITableView was exceeding the limits of the UIScrollView. I will check it and reply. Thanks! – Sagito Jul 31 '13 at 15:51
  • That was actually the problem. My UITableView was a couple pixel bigger than the scroll view and apparently that was causing the problem. Thank you so much! – Sagito Jul 31 '13 at 16:26
0

This worked for me

I programmatically added the tableView to my scroll view using addSubview:

UIGestureRecognizerDelegate is needed.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

    if ([touch.view isDescendantOfView:self.signUpJammerList]) {

        return NO;
    }
    return YES;
}