我有一个包含五个拆分视图控制器的选项卡式应用程序。
在纵向模式下,“主”按钮按预期显示,并且在前两个控制器上,该按钮按预期运行。但是,在最后三个选项卡上,该按钮会导致崩溃并显示以下消息:
-[_UISlidingPopoverLayoutInfo _popoverViewSizeForContentSize:arrowDirection:], /SourceCache/UIKit_Sim/UIKit-1914.84/_UIPopoverLayoutInfo.m:160 中的断言失败 2012-04-24 19:15:38.674 SMToolkit[12420:11303] *由于未捕获的异常而终止应用程序NSInternalInconsistencyException',原因:'未知方向传递给 _popoverViewSizeForContentSize:arrowDirection:'
问题是,这五个视图是从同一来源剪切并粘贴的,几乎是 Apple 的样板。我实际上并没有为弹出框编写故事板,也没有在 prepareforsegue 方法中使用它们,因为从理论上讲,spliltviewcontroller 将它们“免费”提供给我
所有五个 splitviewcontroller 都符合 UISplitViewControllerDelegate
appdelgate 是这样的:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
//Person
UISplitViewController *personSplitViewController = [tabBarController.viewControllers objectAtIndex:1];
UINavigationController *personNavigationController = [personSplitViewController.viewControllers lastObject];
personSplitViewController.delegate = (id)personNavigationController.topViewController;
UINavigationController *personMasterNavigationController = [personSplitViewController.viewControllers objectAtIndex:0];
PersonMasterViewController *personController = (PersonMasterViewController *)personMasterNavigationController.topViewController;
personController.managedObjectContext = self.managedObjectContext;
//Scene
UISplitViewController *sceneSplitViewController = [tabBarController.viewControllers objectAtIndex:2];
UINavigationController *sceneNavigationController = [sceneSplitViewController.viewControllers lastObject];
sceneSplitViewController.delegate = (id)sceneNavigationController.topViewController;
UINavigationController *sceneMasterNavigationController = [sceneSplitViewController.viewControllers objectAtIndex:0];
SceneMasterViewController *sceneController = (SceneMasterViewController *)sceneMasterNavigationController.topViewController;
sceneController.managedObjectContext = self.managedObjectContext;
依此类推,在tabBarController中替换正确的索引
然后在详细视图控制器中,每个控制器都有以下内容(相同,我检查过):
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.title = NSLocalizedString(@"Master", @"Master");
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.masterPopoverController = popoverController;
}
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;
}
在上面,“人”的行为符合预期,但“场景”导致了崩溃。
我在任何视图中都看不到任何关于单击该 barbuttonitem 时发生的情况的任何内容,并且它没有出现在情节提要中。
想法?