UISplitViewController在启动纵向时不显示弹出按钮 [英] UISplitViewController not showing popup button when launching portrait

查看:111
本文介绍了UISplitViewController在启动纵向时不显示弹出按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个基于UISplitViewController的iPad应用程序。当我的应用程序在potrait中启动时,我对toobar按钮有一点问题。不显示显示弹出窗口的按钮。
然而,当我将iPad旋转到横向然后再回到肖像时,按钮显示!

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

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

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 ?

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

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

推荐答案

Kshitiz有正确的概念。首先,我在viewDidLoad方法中设置self.splitviewController.delegate = self,设置此委托有点迟。所以,我试图在早期阶段设置委托,这是awakeFromNib方法。然后它运行良好。

"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.

因此,问题是在viewDidLoad已经加载的视图之后,然后委托将无法工作,它将在某些活动后工作一段时间(例如旋转iPad)。所以比viewDidLoad更早的阶段是awakeFromNib。

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.

这是有效的代码:

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

这篇关于UISplitViewController在启动纵向时不显示弹出按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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