-2
我正在研究iPad應用程序,並且需要創建一個幫助窗口,如果該應用程序是第一次啓動,則會彈出一個幫助窗口。爲此,我做viewDidLayoutSubViews(...)一個小檢查,然後嘗試推出正是如此幫助窗口:iOS:在ViewDidLayoutSubviews中呈現PageViewController時崩潰
[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
墜機事故有什麼錯誤?從'viewDidLayoutSubviews'方法顯示另一個視圖控制器是不合適的。相反,請在應用程序委託中添加支票。如果是第一次啓動應用程序,請從根視圖控制器提供幫助窗口。 – rmaddy
通常情況下,您應該在提問這樣的問題時發佈崩潰日誌和消息。 – Avt
另外'viewDidLoad'更好的地方在開始時展示一些東西。 – Avt