UISplitViewController:如何强制在app启动时显示主popover? (肖像) [英] UISplitViewController: How force to show master popover in app launch? (portrait)

查看:107
本文介绍了UISplitViewController:如何强制在app启动时显示主popover? (肖像)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPad App中我正在使用UISplitViewController。
当应用程序以纵向模式启动时,我需要强制显示主弹出框。

In an iPad App i'm using the UISplitViewController. I need to force to show the master popover when the app launch in portrait mode.

现在我正在使用此代码,它在iOS 5.0上运行良好。

Now I'm using this code and it works well on iOS 5.0.

if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
   if ([[[AppDelegate sharedAppDelegate] splitViewController] respondsToSelector:[[[AppDelegate sharedAppDelegate] btnMenu] action]]) {
      [[[AppDelegate sharedAppDelegate] splitViewController] performSelector:[[[AppDelegate sharedAppDelegate] btnMenu] action]];
   }            
}

但在iOS 5.1中(使用新型主人popover)这种行为似乎是随机的。
有时候popover会全屏显示,有时效果很好。

But in iOS 5.1 (with the new type of master popover) the behaviour seems to be random. Sometimes the popover shows in fullscreen and sometimes works well.

5.1的一些建议?

推荐答案

我在这个问题上挣扎了一段时间,现在我对这个解决方案并不是百分之百满意,但这是我唯一能想到的,给定的当前约束。

I struggled with this one for a while, and even now I'm not 100% happy with the solution, but it is the only thing I've been able to come up with, given the current constraints.

首先,重写以下委托方法:

First, override the following delegate method:

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController

并使用它来获取对条形按钮项的引用,并将其存储在iVar中:

and use it to grab a reference to the bar button item, and store it in an iVar:

barButtonForMaster = barButtonItem;

然后,当你想要显示主视图控制器时,拨打这样的电话:

Then, when you want to show the master view controller, make a call like this:

[barButtonForMaster.target performSelector: barButtonForMaster.action withObject: barButtonForMaster];

如果您想在开始时执行此操作,请使用一些延迟以防止应用崩溃(感谢有用的评论):

In case you want to perform this right at the start, then use some delay in order to prevent app crashing (thanks to the helpful comment):

[barButtonForMaster.target performSelector: barButtonForMaster.action withObject: barButtonForMaster afterDelay:1];

在这种情况下,您可以在拆分视图委托方法中执行选择器。

In that case you can perform the selector right in the split view delegate method.

这篇关于UISplitViewController:如何强制在app启动时显示主popover? (肖像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆