UISplitViewController 启动纵向时不显示弹出按钮

发布于 2024-11-04 08:11:22 字数 1022 浏览 0 评论 0原文

我正在做一个基于 UISplitViewController 的 iPad 应用程序。当我的应用程序以肖像方式启动时,我的工具栏按钮出现了一些问题。不显示显示弹出窗口的按钮。 然而,当我将 iPad 旋转为横向,然后再返回纵向时,按钮会显示!

看起来在启动时不会调用以下方法(这是我有显示按钮的代码):

- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController: (UIPopoverController *)pc

应用程序启动时不会调用此方法,但仅在有旋转时才调用。更奇怪的是,我使用 Xcode UISplitViewController 模板 + 核心数据制作了一个测试应用程序(这与我正在开发的应用程序类似,也是我用来制作此应用程序的模板)。在我没有编写任何代码的测试应用程序上,当我以纵向模式启动应用程序时,按钮会显示,并且在启动时也会调用上面的方法,而不是我的其他应用程序。有人有类似的问题吗?

最后,从苹果文档中还不清楚是否应该在首次显示 UISplitViewController 时调用此方法: http:// developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewControllerDelegate_protocol/Reference/Reference.html%23//apple_ref/doc/uid/TP40009454

I am doing an iPad app based on a UISplitViewController. I have a little problem with the toobar button when my app launched in potrait. The button to show the popover is not displayed.
However when I rotate my iPad into landscape and then back to portrait, the button shows !

It looks like the following method is not called on launch (this is were I have the code showing the button):

- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController: (UIPopoverController *)pc

This method is not called when the app launches but only when there is a rotation. What is even stranger is that I made a test app using Xcode UISplitViewController template + core data (which is similar to the app I am working on, and is the template I used to make this app). On the test app on which I have not made a single line of code, the button shows when I launch my app in portrait mode and the method above is also called upon launching, as opposed to my other app. Does anyone had a similar problem ?

Finally, it is not very clear from apple documentation whether this method is supposed to be called when a UISplitViewController is first shown:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewControllerDelegate_protocol/Reference/Reference.html%23//apple_ref/doc/uid/TP40009454

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

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

发布评论

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

评论(6

心舞飞扬 2024-11-11 08:11:22

“Kshitiz”的概念是正确的。首先我在viewDidLoad方法中设置了self.splitviewController.delegate = self,现在设置这个委托有点晚了。因此,我尝试在早期阶段设置委托,即 awakeFromNib 方法。然后效果很好。

所以,问题是在视图已经被 viewDidLoad 加载之后,委托将不起作用,它会在某些活动(例如旋转 iPad)后一段时间起作用。所以比viewDidLoad更早的阶段是awakeFromNib。

这是有效的代码:

- (void) awakeFromNib{
    [super awakeFromNib];
    self.splitViewController.delegate = self;
}

"Kshitiz" has the right concept. first I set the self.splitviewController.delegate = self in the viewDidLoad method, which it is a bit late to set this delegation. So, I tried to set the delegation in earlier stage which is awakeFromNib method. Then it works well.

So, the problem is after view already loaded by viewDidLoad, then the delegation will not work, it will work some time after some activities (such as rotate the iPad). So the earlier stage than viewDidLoad is awakeFromNib.

Here is the code that works:

- (void) awakeFromNib{
    [super awakeFromNib];
    self.splitViewController.delegate = self;
}
迟月 2024-11-11 08:11:22

您是否设置了 splitviewcontroller 委托?
通常,当未设置委托时会出现问题。

Have you set a splitviewcontroller delegate?
Generally the problem arises when delegate is not set.

浅唱ヾ落雨殇 2024-11-11 08:11:22

我遇到了完全相同的问题,Martin Gunnarsson 的回应引导我找到了解决方案。

之前,我在 viewDidLoad: 中加载委托视图(详细信息视图)后设置 UISplitViewController 的委托属性。此时,UISplitViewController 已经发送了初始 splitViewController:willHideViewController:withBarButtonItem:forPopoverController: 消息。我只是没有尽快设置代表。

解决方案是在主应用程序委托中的 application:DidFinishLaunchingWithOptions: 中分配委托。在本例中,我的委托包含在导航控制器中,因此我必须深入挖掘一层才能获取它。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
    UINavigationController *mainNavigationController = (UINavigationController *)[splitViewController.viewControllers objectAtIndex:1];
    HPMainViewController *mainViewController = [mainNavigationController.viewControllers objectAtIndex:0]; 

    splitViewController.delegate = mainViewController;
    return YES;
}

I was having the exact same problem, and Martin Gunnarsson's response led me to the solution.

Before, I was setting the UISplitViewController's delegate property after the delegate view (the detail view) had already been loaded, in viewDidLoad:. By this time, the UISplitViewController had already sent the initial splitViewController:willHideViewController:withBarButtonItem:forPopoverController: message. I simply hadn't set the delegate soon enough.

The solution was to assign the delegate in the main app delegate, in application:DidFinishLaunchingWithOptions:. In this case, my delegate was contained within a navigation controller, so I had to dig one layer deeper to get it.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
    UINavigationController *mainNavigationController = (UINavigationController *)[splitViewController.viewControllers objectAtIndex:1];
    HPMainViewController *mainViewController = [mainNavigationController.viewControllers objectAtIndex:0]; 

    splitViewController.delegate = mainViewController;
    return YES;
}
寻找我们的幸福 2024-11-11 08:11:22

这也让我感到空闲,尤其是因为我正在使用开箱即用的 splitViewController 处理两个 iPad 项目,并且第一个项目总是显示“Master”按钮,而第二个项目则从未显示。我比较了outlet、relationship和delegate,直到我眼花缭乱,但最终在appDelegate中找到了答案。事实证明,我在应用程序中注释了太多:didFinishLaunchingWithOptions:,特别是在设置 splitViewController.delegate 的地方。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
        UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
        splitViewController.delegate = (id)navigationController.topViewController;
    }

将其添加到 appDelegate 中可以使您不必子类化 splitViewController。
我还尝试连接 IB 中的代表,但由于某种原因它没有这些。故事板设计缺陷,恕我直言。

This drove me spare as well, the more so since I'm working on two iPad projects with out-of-the-box splitViewController and the first one always shows the 'Master' button while the second one never did. I compared outlets and relationships and delegates until I was cross-eyed, but finally found the answer in the appDelegate. It turned out I had commented out a bit too much in the application:didFinishLaunchingWithOptions:, specifically where the splitViewController.delegate is set.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
        UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
        splitViewController.delegate = (id)navigationController.topViewController;
    }

Adding this to the appDelegate saves you from having to subclass the splitViewController.
I also tried connecting the delegate in IB, but for some reason it wouldn't have none of that. Storyboard design flaw, imho.

少女七分熟 2024-11-11 08:11:22

我被困在这个问题上有一段时间了。终于开始工作了。 awakeFromNib 对我不起作用。 didFinishLaunchingWithOptions 做到了。可能是因为我正在运行一些查询来填充弹出窗口控制器中的项目。

I was stuck on this for quite sometime. Finally got it to work. The awakeFromNib did not work for me. The didFinishLaunchingWithOptions did. Might be because I am running some query that populates the items in the popover controller.

梦晓ヶ微光ヅ倾城 2024-11-11 08:11:22

我有同样的问题。我的观点是在IB中建立的,看来这是一个时间问题。在分割视图通知初始方向“更改”后,分割视图委托将被设置。将分割视图添加到应用程序委托中的出口使得该按钮在我的纵向启动时出现,但是当我打开弹出窗口时它是空的。这可能可以通过某种方式解决,但我认为奇怪的是,分割视图在设置时没有通知其委托当前方向。

I'm having the same issue. My view is set up in IB, and it seems this is a timing issue. The split view delegate gets set after the split view has notified about the initial orientation "change". Adding the split view to an outlet in the app delegate made the button appear at portrait startup for me, but when I open the popup it's empty. This can probably be worked around somehow, but I think it's weird that the split view doesn't notify its delegate about the current orientation when it's set.

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