我在找UIPageViewController,找到了这个:http://www.ioslearner.com/implementing-uipageviewcontroller-programatically-without-storyboarding/
这很可疑。为什么它最初插入一个只有1个viewController的数组。
所以我写了一个程序尝试插入2-10。如果我一开始只需插入1个viewController,程序就可以工作。但是,如果我尝试插入2-10,它不起作用。
[self.containerView addSubview:self.pageViewController.view];
self.pageViewController.view.frame = self.containerView.bounds;
NSMutableArray * arrayOfControllers=[NSMutableArray array];
for (int i = 0; i<1 ; i++) { //if I set this into for (int i = 0; i<10 ; i++) { instead it wouldn't work
BlankImageViewController *contentViewController = [[BlankImageViewController alloc] init];
contentViewController.view.frame = self.containerView.bounds;
[arrayOfControllers addObject:contentViewController];
//contentViewController.labelContents = [self.modelArray objectAtIndex:0];
}
NSArray *viewControllers = @[arrayOfControllers.lastObject];
viewControllers = [NSArray arrayWithArray:arrayOfControllers]; //If this line is commented it works
[self.pageViewController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];如果viewControllers只有一个元素,那么它就可以工作。self.pageViewController.viewControllers将用这1个元素填充。
如果viewControllers有多个元素,那么事情就不再有效了。self.pageViewController.viewControllers将具有空数组。
我想知道为什么。我是UIPageViewController的新手。如果您只能填充一个数组,为什么还要一个UIViewController呢?
发布于 2012-10-18 00:26:40
如果一次只显示一个页面,则有一个视图控制器。如果一次显示两个页面,则有两个视图控制器。
顺便说一句,我的书教你如何开始使用Page View Controller:
http://www.apeth.com/iOSBook/ch19.html#_page_view_controller
但我还没有为iOS 6和新的滚动过渡样式更新它。
https://stackoverflow.com/questions/12938530
复制相似问题