未调用 UISplitViewController 委托方法

发布于 2024-10-11 21:39:17 字数 2070 浏览 6 评论 0原文

我在 UITabBarController 中使用 UISplitViewController,在分割视图的主窗格中使用普通的 UIViewControllerUINavigationController > 在详细信息窗格中,它本身包含一个普通的 UIViewController

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

我的问题是分割视图的委托方法,即。 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”应该这样做时,这似乎是非常错误的。

I am using a UISplitViewController inside a UITabBarController with a plain UIViewController in the master pane of the split view and a UINavigationController in the detail pane, which itself contains a vanilla UIViewController.

I am aware that Apple advise to use split views at the root level only, however I have seen other applications (eg, Amazon- 'Wish List' tab) that use split views in tabs so I'm sure it's possible.

My problem is that the delegate methods of the split view, ie. those in UISplitViewControllerDelegate do not get called, which prevents me from creating my pop-over menu when switching into Portrait mode.

The methods in question are the following -

// 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;

The UISplitViewController does receive the rotation notifications.

I can get the willShowViewController method to be called if I force the status bar orientation to landscape right (or left) at the beginning of the app launch, using

 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

However, the willHideViewController doesn't get called. And I don't want to force the app to start in landscape. If I do the same thing but force it to portrait, I don't receive the callbacks.

I don't understand why the split view controller is not calling it's delegate methods when it is otherwise behaving correctly. These methods should be called from its method-

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

internally, and when I breakpoint inside this, I can check that the delegate is set and that it is still alive.

Been stuck on this all day! Everything else is working great and I'm very pleased that the splitview / tabbar / navbar combination is working well. I just need these notifications.

Should I perhaps just call them manually when I rotate? Seems very wrong when the `UISplitViewController' should be doing this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请远离我 2024-10-18 21:39:17

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

Solved, it has to be at either root level or a direct subview of a tabBar which also must be at root level. Annoying!

从此见与不见 2024-10-18 21:39:17

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

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

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

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

因此,在某个地方,如果您错过了以下调用,

splitView.delegate = detailView;

detailView 将永远不会收到方向更改等通知。至少这是我陷入困境的地方。

First, try to see if you are setting the correct delegates.
e.g., lets say you created three controllers,

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

You implemented the delegate protocol at the detail view, so that when orientation changes, detail view should be able to put a button in the toolbar.

Now in order for splitView to call this function from delegate, you need to set the delegate itself.

So somewhere, if you are missing the following call,

splitView.delegate = detailView;

detailView's will never get notified of the orientation changes etc. At least this is where I was stuck.

灯下孤影 2024-10-18 21:39:17

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

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

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

I like the following method of sending a message from the master UIViewController to the detail UIViewController. Somewhere inside the master's implementation:

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

This is from Paul Hegarty's Fall 2011 Stanford iTunesU iPad and iPhone Application Development course.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文