I have this code snippet in a view controller that conforms to UIPageViewControllerDataSource
protocol:
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *tempViewControllers = [[NSMutableArray alloc] init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
[tempViewControllers addObject:[storyboard instantiateViewControllerWithIdentifier:@"page1Controller"]];
[tempViewControllers addObject:[storyboard instantiateViewControllerWithIdentifier:@"page2Controller"]];
[tempViewControllers addObject:[storyboard instantiateViewControllerWithIdentifier:@"page3Controller"]];
[tempViewControllers addObject:[storyboard instantiateViewControllerWithIdentifier:@"page4Controller"]];
[tempViewControllers addObject:[storyboard instantiateViewControllerWithIdentifier:@"page5Controller"]];
self.pages = [NSArray arrayWithArray:tempViewControllers];
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"pageViewController"];
self.pageViewController.dataSource = self;
Page1ViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
// Change the size of page view controller
self.pageViewController.view.frame = CGRectMake(0, 0, self.containerView.frame.size.width, self.containerView.frame.size.height);
[self addChildViewController:self.pageViewController];
[self.containerView addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
[self.view bringSubviewToFront:self.headerView];
}
This is working when I run the app in iOS 8
and in iOS 9
, but when I run it in iOS 7
, I see in Xcode that the CPU reaches around 93% of workload, and the app gets blocked and unresponsive.
If I comment the call to [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
the app runs normally (but I need such call)...
What could be happening here?