ios - 页面 View Controller 数据源
<p><div>
<aside class="s-notice s-notice__info post-notice js-post-notice mb16"role="status">
<div class="d-flex fd-column fw-nowrap">
<div class="d-flex fw-nowrap">
<div class="flex--item wmn0 fl1 lh-lg">
<div class="flex--item fl1 lh-lg">
<b>关闭</b>。这个问题需要<a href="https://stackoverflow.com/help/closed-questions" rel="noreferrer noopener nofollow">details or clarity</a> .它目前不接受答案。
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>基本上你有一个 UIPageViewController。它当前在所有 N 个页面中的索引 K 处显示一个页面。 UIPageViewController 需要知道正在显示的当前页面之前的页面(在索引 K 处)和当前页面之后的页面。</p>
<p>看起来是这样的:</p>
<pre><code>//Called on the data source. Returns the UIViewController before the
//current one (viewController) within the UIPageViewController (pageViewController)
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)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 ;
}
</code></pre>
<p>对于第二种方法,它做同样的事情,但试图获取之后的页面。同样,iOS 需要了解这些信息,以便在用户更改页面时快速呈现该页面。</p>
<pre><code>- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)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 == ) {
//there's no page after it
return nil;
}
//otherwise, return the next UIViewController
return ;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 页面 ViewController 数据源,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33087447/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33087447/
</a>
</p>
页:
[1]