gpt4 book ai didi

ios - 在 UIPageViewController 中手动切换 View 导致异常

转载 作者:行者123 更新时间:2023-11-28 22:11:49 24 4
gpt4 key购买 nike

我有一个 UIPageViewController,它显示两个 UIViewController 并允许用户在两​​者之间滑动。我实现了一个按钮,允许用户在两​​者之间手动切换。执行它的代码如下:

[self setViewControllers:@[[self.storyboard instantiateViewControllerWithIdentifier:@"PlayersViewController"]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:^(BOOL completion){}];

不幸的是,每次我按下按钮,我都会得到一个异常:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'

我从扩展 UIPageViewControllerDelegate 的自定义类中调用该方法。

如有任何帮助,我们将不胜感激!

**编辑:

以下是我的自定义类的相关部分:

- (void)viewDidLoad
{
[super viewDidLoad];

self.dataSource = self;
gvc = [[GamesViewController alloc] init];
pvc = [[PlayersViewController alloc] init];
[self setViewControllers:@[[self.storyboard instantiateViewControllerWithIdentifier:@"GamesViewController"]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}

- (void) slidepage
{
[self setViewControllers:@[[self.storyboard instantiateViewControllerWithIdentifier:@"PlayersViewController"]] direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:^(BOOL completion){NSLog(@"hihi");}];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
if ([viewController isKindOfClass:[GamesViewController class]])
return nil;

return [self.storyboard instantiateViewControllerWithIdentifier:@"GamesViewController"];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
if ([viewController isKindOfClass:[PlayersViewController class]])
return nil;

return [self.storyboard instantiateViewControllerWithIdentifier:@"PlayersViewController"];
}

最佳答案

好像是

[self.storyboard instantiateViewControllerWithIdentifier:@"PlayersViewController"]

返回 nil。这意味着要么 self.storyboardnil,要么 Storyboard找不到给定标识符的 View Controller 。

关于ios - 在 UIPageViewController 中手动切换 View 导致异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22737480/

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