iOS:在ViewDidLayoutSubviews中呈现PageViewController时崩溃

时间:2014-02-20 23:19:27

标签: ios objective-c user-interface

我正在开发一款iPad应用程序,我需要创建一个帮助窗口,如果该应用程序首次启动,该窗口会弹出。为此,我在viewDidLayoutSubViews(...)中进行了一些小检查,然后尝试启动帮助窗口:

    [self getHelpImages];
    self.fPageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
    self.fPageViewController.dataSource = self;
    PageContentViewController* startingViewController = [self viewControllerAtIndex:0];
    NSArray *viewControllers = @[startingViewController];
    [self.fPageViewController setViewControllers:viewControllers
                                       direction:UIPageViewControllerNavigationDirectionForward
                                        animated:NO
                                      completion:nil];

    // Change the size of page view controller
    self.fPageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);
    [self.fPageViewController setModalPresentationStyle:UIModalPresentationFormSheet];
    [self.fPageViewController setDefinesPresentationContext:YES];
    [self presentViewController:self.fPageViewController animated:YES completion:nil];

其中'fPageViewController'的类型为UIPageViewController。问题是我遇到了崩溃,我不知道为什么。我的第一个怀疑是fPageViewController是零,但它正在块的顶部实例化。有什么想法吗?

编辑:这是一个跟踪片段:

frame #9: 0x03f56448 CoreFoundation`+[NSException raise:format:arguments:] + 136
frame #10: 0x0246b23e Foundation`-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
frame #11: 0x01312e8b UIKit`-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 192
frame #12: 0x0108b78c UIKit`-[UIViewController presentViewController:withTransition:completion:] + 6433
frame #13: 0x0108bcaf UIKit`-[UIViewController presentViewController:animated:completion:] + 130
frame #14: 0x00016bb8 Bones`-[ViewController viewDidLayoutSubviews](self=0x0ba29400, _cmd=0x016e943b) + 27288 at ViewController.mm:1158

1 个答案:

答案 0 :(得分:0)

好的,看起来我们应该使用viewDidAppear。移动代码就完美了。