IOS:通过PageViewController显示WebView
Posted
技术标签:
【中文标题】IOS:通过PageViewController显示WebView【英文标题】:IOS:Showing WebView through PageViewController 【发布时间】:2015-12-16 06:18:16 【问题描述】:在我的项目中,我使用UIPageViewController
在主页上显示一条视频。为了显示视频,我在UIPageViewController
上使用UIWebView
。
最初我在上面使用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;
【问题讨论】:
【参考方案1】:错误表明您正在尝试将 nil 插入数组。在此行之前设置断点:
NSArray *viewControllers = @[startingViewController];
startingViewController 可能是 nil。
【讨论】:
以上是关于IOS:通过PageViewController显示WebView的主要内容,如果未能解决你的问题,请参考以下文章
故事板ios中具有不同页面视图的PageViewController
如何在 iOS 中将集合与 pageviewcontroller 一起使用
滚动视图内的pageviewcontroller内的iOS tableview