UISplitViewController 中缺少 UIBarButtonItem
我在 UISplitViewController 内的右侧视图控制器中缺少带有弹出窗口的 navigationItem。当我将 iPad 旋转至纵向方向时,该按钮不会出现。代码很好,我已经多次使用相同的代码(当然不是绝对),但现在我遇到了这个奇怪的错误。
- (void)splitViewController:(UISplitViewController *)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)pc
{
barButtonItem.title = aViewController.title;
self.navigationItem.rightBarButtonItem = barButtonItem;
/*
this method gets called, class is set to be delegate of split view,
barButtonItem && self.navigationItem are not nils.
*/
}
- (void)splitViewController:(UISplitViewController *)svc
willShowViewController:(UIViewController *)aViewController
invalidatingBarButtonItem:(UIBarButtonItem *)button
{
self.navigationItem.rightBarButtonItem = nil;
}
所有这些东西都是使用这样的代码创建的......
UISplitViewController *svc = [[UISplitViewController alloc] init];
UINavigationController *rightNav = [[UINavigationController alloc] init];
DetailViewController *dvc = [[DetailViewController alloc] initWithSomeArgs:args];
[rightNav pushViewController:dvc animated:NO];
svc.delegate = dvc;
svc.viewControllers = [NSArray arrayWithObjects:tabBarController, rightNav, nil];
// tabBar is good, not nil and working well on the iPhone
[self.window addSubview:svc.view];
[dvc release]; [rightNav release];
我不知道为什么这不起作用,我需要尽快弄清楚。请帮助我。
I've got missing navigationItem with popover in my right-hand view controller inside UISplitViewController. Simply the button do not appears when I'm rotating iPad to portrait orientation. The code is just fine, I have used the same one (not absolutely of course) many times, but right now i have got this weird bug.
- (void)splitViewController:(UISplitViewController *)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)pc
{
barButtonItem.title = aViewController.title;
self.navigationItem.rightBarButtonItem = barButtonItem;
/*
this method gets called, class is set to be delegate of split view,
barButtonItem && self.navigationItem are not nils.
*/
}
- (void)splitViewController:(UISplitViewController *)svc
willShowViewController:(UIViewController *)aViewController
invalidatingBarButtonItem:(UIBarButtonItem *)button
{
self.navigationItem.rightBarButtonItem = nil;
}
All of this stuff gets created using the code like this...
UISplitViewController *svc = [[UISplitViewController alloc] init];
UINavigationController *rightNav = [[UINavigationController alloc] init];
DetailViewController *dvc = [[DetailViewController alloc] initWithSomeArgs:args];
[rightNav pushViewController:dvc animated:NO];
svc.delegate = dvc;
svc.viewControllers = [NSArray arrayWithObjects:tabBarController, rightNav, nil];
// tabBar is good, not nil and working well on the iPhone
[self.window addSubview:svc.view];
[dvc release]; [rightNav release];
I have no idea why that doesn't work, and I need to figure it out ASAP. Help me please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有类似的问题。我有一个主从应用程序并正在使用情节提要。我的详细视图控制器嵌入在导航控制器中。 UISplitViewControllerDelegate 方法已正确实现,并且在设备旋转时调用它们。栏按钮已正确添加,但不可见。
问题原因:在我的详细视图控制器的故事板中,我手动添加了一个导航栏,因为我没有看到任何导航栏。然而,这与我添加按钮的导航栏不同。正确的导航栏隐藏在故事板中,因此在我的应用程序中不可见。
解决方案:我转到情节提要中的详细视图控制器,并删除了手动添加的导航栏。然后,我单击了导航控制器。在“属性检查器”下,我选中了标有“显示导航栏”的框。现在,正确的栏在我的导航控制器和详细视图控制器以及我的应用程序中都可见。
I had a similar issue. I had a Master-Detail application and was using Storyboards. My Detail View Controller was embedded in a Navigation Controller. The UISplitViewControllerDelegate methods were implemented properly and they were being called when the device rotated. The bar button was being added correctly, but wasn't visible.
Cause of the problem: In Storyboards in my Detail View Controller, I had added a navigation bar manually, since I didn't see any navigation bar otherwise. However, this was not the same navigation bar as the one I was adding the button to. The correct navigation bar was hidden in Storyboards, and thus not visible in my app.
Solution: I went to my Detail View Controller in Storyboards and deleted the navigation bar I had added manually. Then, I clicked on the Navigation Controller. Under 'Attributes inspector', I checked the box labeled 'Shows Navigation Bar'. Now, the correct bar was visible in both my Navigation Controller and my Detail View Controller, as well as my app.
看起来您错过了 DetailViewController 和 UISplitViewController 之间的引用出口。
It looks like you have missed the referencing outlet between your DetailViewController and the UISplitViewController.