在我的项目中,我使用UIPageViewController
在主页上显示视频条。用于显示我在UIWebView
上使用UIPageViewController
的视频。
最初我使用UIImageView
并且它工作正常但是当我应用UIWebView
时它会出错:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
请帮助我解决这个问题
我正在分享我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Create the data model
//_pageTitles = @[@"Over 200 Tips and Tricks", @"Discover Hidden Features", @"Bookmark Favorite Tip", @"Free Regular Update"];
//_pageImages = @[@"https://www.youtube.com/embed/uObzRhWq7tk", @"Radio_Button-512.png", @"page3.png", @"page4.png"];
_videourl = @[@"https://www.youtube.com/embed/uObzRhWq7tk",@"https://www.youtube.com/embed/38DZgGjaPOA"];
// Create page view controller
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
self.pageViewController.dataSource = self;
PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
// Change the size of page view controller
self.pageViewController.view.frame = CGRectMake(0, CGRectGetMaxY(searchbtn.frame)+80, self.view.frame.size.width, self.view.frame.size.height/3);
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
}
和
- (PageContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.pageTitles count] == 0) || (index >= [self.pageTitles count]))
{
return nil;
}
// Create a new view controller and pass suitable data.
PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageContentViewController"];
pageContentViewController.imageFile = self.pageImages[index];
pageContentViewController.titleText = self.pageTitles[index];
pageContentViewController.urlFile = self.videourl[index];
pageContentViewController.pageIndex = index;
return pageContentViewController;
}
答案 0 :(得分:1)
错误说您正在尝试将nil插入数组中。在此行之前设置断点:
NSArray *viewControllers = @[startingViewController];
startingViewController 可能是 nil 。