关闭。这个问题需要
details or clarity .它目前不接受答案。
Best Answer-推荐答案 strong>
基本上你有一个 UIPageViewController。它当前在所有 N 个页面中的索引 K 处显示一个页面。 UIPageViewController 需要知道正在显示的当前页面之前的页面(在索引 K 处)和当前页面之后的页面。
看起来是这样的:
//Called on the data source. Returns the UIViewController before the
//current one (viewController) within the UIPageViewController (pageViewController)
- (UIViewController *)pageViewControllerUIPageViewController *)pageViewController viewControllerBeforeViewControllerUIViewController *)viewController
{
//gets the index of the page currently showing
NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
//Checks that it's not the first page and that it's
//actually a part of the UIPageViewController
if ((index == 0) || (index == NSNotFound)) {
//If it is, then there is no page before it.
return nil;
}
//otherwise, lets go back one index
index--;
//and then this is the UIViewController before it
return [self viewControllerAtIndex:index];
}
对于第二种方法,它做同样的事情,但试图获取之后的页面。同样,iOS 需要了解这些信息,以便在用户更改页面时快速呈现该页面。
- (UIViewController *)pageViewControllerUIPageViewController *)pageViewController viewControllerAfterViewControllerUIViewController *)viewController
{
//gets the index of the current page being shown
NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
//if it's not found, then there isn't a page after it
if (index == NSNotFound) {
return nil;
}
//go to the next index
index++;
//if we're at the end of the pages
if (index == [self.pageTitles count]) {
//there's no page after it
return nil;
}
//otherwise, return the next UIViewController
return [self viewControllerAtIndex:index];
}
关于ios - 页面 View Controller 数据源,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/33087447/