9

我在拆分视图的主窗格中使用了一个UISplitViewController内部 aUITabBarController和一个普通的 a在详细窗格中,它本身包含一个 vanilla 。UIViewControllerUINavigationControllerUIViewController

我知道 Apple 建议仅在根级别使用拆分视图,但是我看到其他应用程序(例如,亚马逊-“愿望清单”选项卡)在选项卡中使用拆分视图,所以我确信这是可能的。

我的问题是拆分视图的委托方法,即。中的那些UISplitViewControllerDelegate不会被调用,这会阻止我在切换到纵向模式时创建弹出菜单。

有问题的方法如下 -

// Called when a button should be added to a toolbar for a hidden view controller
- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc;

// Called when the view is shown again in the split view, invalidating the button and popover controller
- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem;

// Called when the view controller is shown in a popover so the delegate can take action like hiding other popovers.
- (void)splitViewController: (UISplitViewController*)svc popoverController: (UIPopoverController*)pc willPresentViewController:(UIViewController *)aViewController;

UISplitViewController 确实会收到轮换通知。

如果我在应用程序启动开始时强制状态栏方向向右(或向左)横向,我可以调用 willShowViewController 方法,使用

 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

但是,willHideViewController不会调用。而且我不想强制应用程序以横向方式启动。如果我做同样的事情但强迫它纵向,我不会收到回调。

我不明白为什么拆分视图控制器在正常运行时没有调用它的委托方法。这些方法应该从它的方法中调用——

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

在内部,当我在其中设置断点时,我可以检查委托是否已设置并且它仍然存在。

整天卡在这上面!其他一切都运行良好,我很高兴 splitview / tabbar / navbar 组合运行良好。我只需要这些通知。

我应该在旋转时手动调用它们吗?当 `UISplitViewController' 应该这样做时似乎非常错误。

4

3 回答 3

6

已解决,它必须位于根级别或 tabBar 的直接子视图,该子视图也必须位于根级别。恼人的!

于 2011-01-18T17:29:05.110 回答
3

首先,尝试查看您是否设置了正确的代表。例如,假设您创建了三个控制器,

UISplitViewController* splitView;
UIViewController* masterView;
UIViewController* detailView;

您在详细视图中实现了委托协议,因此当方向更改时,详细视图应该能够在工具栏中放置一个按钮。

现在为了让 splitView 从委托中调用此函数,您需要设置委托本身。

所以在某个地方,如果你错过了下面的电话,

splitView.delegate = detailView;

detailView 永远不会收到有关方向更改等的通知。至少这是我被卡住的地方。

于 2012-01-06T15:43:17.973 回答
2

我喜欢以下从主 UIViewController 向详细 UIViewController 发送消息的方法。在主实现中的某个地方:

id detailViewController = [[self.splitViewController viewControllers] lastObject];
[detailViewController setSomeProperty:…];

这是来自 Paul Hegarty 的 2011 年秋季斯坦福 iTunesU iPad 和 iPhone 应用程序开发课程。

于 2012-12-09T06:18:54.783 回答