简体   繁体   中英

UITableView inside UIScrollView with date

I want to show a UITableView inside UIScrollView. In UITableView header I want to show the current date at first and then if the user scrolls left it should show the previous date and if the user scrolls right is should show the next date... And I want to disable the vertical scrolling...

Here's my code

- (void)viewDidLoad {
self.title = @"2017-02-01";

_scrollView.delegate = self;
_scrollView.pagingEnabled = YES;
_scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.scrollView.frame) * 3, CGRectGetHeight(self.scrollView.frame));
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.scrollsToTop = NO;
}

With this I can scroll right for 1 time and then its not scrolling. I tried some solutions but its not working...

Your best bet is to use the UIPageViewController , which does exactly as you need.

Every time the user swipes left or right, the page view controller asks for the previous or next view controller - which will be an new instance of your view controller containing a UITableView (set up for the required date).

And to disable scrolling on the table, use tableView.scrollEnabled = NO . (Table views can only scroll vertically, so this will disable vertical scrolling).

In the Attributes Inspector, you can uncheck the tick at Scrolling Enabled inorder to disable vertical scrolling.

You can check on this picture

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM