简体   繁体   English

UIScrollView里面的UITableView带有日期

[英]UITableView inside UIScrollView with date

I want to show a UITableView inside UIScrollView. 我想在UIScrollView中显示一个UITableView。 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... 在UITableView标题中,我想首先显示当前日期,然后如果用户向左滚动它应显示上一个日期,如果用户向右滚动则应显示下一个日期...并且我想禁用垂直滚动.. 。

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. 您最好的选择是使用UIPageViewController ,它完全按照您的需要进行操作。

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). 每次用户向左或向右滑动时,页面视图控制器都会询问上一个或下一个视图控制器 - 它将是包含UITableView(设置为所需日期)的视图控制器的新实例。

And to disable scrolling on the table, use tableView.scrollEnabled = NO . 要禁用表上的滚动,请使用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 你可以查看这张照片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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