UIPageViewControllerDataSourceでViewControllerを返すときに、先頭と末尾をくっつければよし。
XCodeのサンプルコードのModelController.mを↓とする。
ModelController.m
#pragma mark - Page View Controller Data Source
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [self indexOfViewController:(DataViewController *)viewController];
if( index == NSNotFound){
return nil;
}
if (index == 0) {
// 先頭に行ってたら最後のControllerを返す(=ループ)
index = [self.pageData count]-1;
}else{
index--;
}
return [self viewControllerAtIndex:index storyboard:viewController.storyboard];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = [self indexOfViewController:(DataViewController *)viewController];
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageData count]) {
// 末尾に行ってたら先頭のControllerを返す(=ループ)
index = 0;
}
return [self viewControllerAtIndex:index storyboard:viewController.storyboard];
}