gpt4 book ai didi

IOS:通过PageViewController显示WebView

转载 作者:行者123 更新时间:2023-11-29 01:23:34 25 4
gpt4 key购买 nike

在我的项目中,我使用 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;
}

最佳答案

错误表明您正在尝试将 nil 插入数组。在此行之前设置一个断点:

 NSArray *viewControllers = @[startingViewController];

startingViewController 可能是 nil

关于IOS:通过PageViewController显示WebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34305157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com