3 回答

TA貢獻1874條經驗 獲得超12個贊
是的,可以使用以下方法:
- (void)setViewControllers:(NSArray *)viewControllers
direction:(UIPageViewControllerNavigationDirection)direction
animated:(BOOL)animated
completion:(void (^)(BOOL finished))completion;`
這與在頁面上設置第一個視圖控制器的方法相同。類似,您可以使用它來轉到其他頁面。
不知道為什么viewControllers是數組,而不是單個視圖控制器?
那是因為頁面視圖控制器可以有一個“書脊”(就像在iBooks中一樣),一次顯示2頁內容。如果一次顯示1頁內容,則只傳入1元素數組。
Swift中的一個例子:
pageContainer.setViewControllers([displayThisViewController], direction: .Forward, animated: true, completion: nil)

TA貢獻1810條經驗 獲得超4個贊
這是單個分頁視圖的另一個代碼示例。這里省略了viewControllerAtIndex的實現,它應該返回給定索引的正確視圖控制器。
- (void)changePage:(UIPageViewControllerNavigationDirection)direction {
NSUInteger pageIndex = ((FooViewController *) [_pageViewController.viewControllers objectAtIndex:0]).pageIndex;
if (direction == UIPageViewControllerNavigationDirectionForward) {
pageIndex++;
}
else {
pageIndex--;
}
FooViewController *viewController = [self viewControllerAtIndex:pageIndex];
if (viewController == nil) {
return;
}
[_pageViewController setViewControllers:@[viewController]
direction:direction
animated:YES
completion:nil];
}
可以通過調用更改頁面
[self changePage:UIPageViewControllerNavigationDirectionReverse];
[self changePage:UIPageViewControllerNavigationDirectionForward];
- 3 回答
- 0 關注
- 658 瀏覽
添加回答
舉報