将UIPageViewController添加为子视图控制器时出错

时间:2016-09-30 06:35:31

标签: ios objective-c uiviewcontroller uistoryboard

我收到以下错误:

  

*由于未捕获的异常'NSInvalidArgumentException'而终止应用,原因:'*

     

- [__ NSArrayM insertObject:atIndex:]:object不能为nil'

这是我的代码:

UIViewController *p1 = [storyboard instantiateViewControllerWithIdentifier:@"First"];
NSLog(@" p1    %@",p1);
UIViewController *p2 = [storyboard
                        instantiateViewControllerWithIdentifier:@"Second"];
UIViewController *p3 = [storyboard
                        instantiateViewControllerWithIdentifier:@"Third"];
UIViewController *p4 = [storyboard
                        instantiateViewControllerWithIdentifier:@"Fourth"];

_Array = @[p1,p2,p3,p4];

NSLog(@"%@",_Array);

self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;

[[self.pageViewController view] setFrame:CGRectMake(0, 0, 320, 500)];

[_pageViewController setViewControllers:@[p1]
                                  direction:UIPageViewControllerNavigationDirectionForward
                                   animated:NO
                                 completion:nil];

[self.pageViewController willMoveToParentViewController:self];
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];

0 个答案:

没有答案