UITableView scrolling problems when inside a UIScr

2020-03-01 20:11发布

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!

4条回答
可以哭但决不认输i
2楼-- · 2020-03-01 20:45

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;
}
查看更多
祖国的老花朵
3楼-- · 2020-03-01 20:46

Try to set

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

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

查看更多
我想做一个坏孩纸
4楼-- · 2020-03-01 20:49

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
查看更多
Emotional °昔
5楼-- · 2020-03-01 21:10

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!

查看更多
登录 后发表回答