子笔尖中的工具栏项目 [英] Toolbar items in sub-nib

查看:70
本文介绍了子笔尖中的工具栏项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前可能已经提出过这个问题,但是我的google-fu必须不如别人的,因为我无法理解这一点。

This question has probably been asked before, but my google-fu must be inferior to everybody else's, cause I can't figure this out.

我是玩iPhone SDK,我正在构建一个我一直在考虑的概念应用程序。如果我们看看使用基于导航的应用程序生成的骨架,MainWindow.xib包含一个导航控制器,并在其中包含一个根视图控制器(如果您稍微玩一下,还可以使用导航栏和工具栏)。根视图控制器具有与之关联的RootViewController-nib,用于加载表视图。

I'm playing around with the iPhone SDK, and I'm building a concept app I've been thinking about. If we have a look at the skeleton generated with a navigation based app, the MainWindow.xib contains a navigation controller, and within that a root-view controller (and a navigation bar and toolbar if you play around with it a little). The root-view controller has the RootViewController-nib associated with it, which loads the table-view.

到目前为止一切顺利。要将内容添加到工具栏和导航栏,我应该将它们添加到根视图控制器下面的层次结构中(这没有问题)。但是,我无法弄清楚的是,这仍然在MainWindow.xib中(或者,在运行时,nib)。如何定义xib以便从中获取工具栏项目?

So far so good. To add content to the tool bar and to the navigation bar, I'm supposed to add those to in the hierarchy below the Root View Controller (which works, no problem). However, what I can't figure out is, this is all still within the MainWindow.xib (or, at runtime, nib). How would I define a xib in order for it to pick up tool bar items from that?

我想做(相当于,只是在这里重用名称)

I want to do (the equivalent of, just reusing the name here)

RootViewController *controller = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller release];

并在该笔尖中定义的工具栏项目上获取导航控制器。放置它的逻辑位置将在File的所有者(类型为RootViewController)下的层次结构中,但似乎不可能。

and have the navigation controller pick-up on the tool bar items defined in that nib. The logical place to put it would be in the hierarchy under File's Owner (which is of type RootViewController), but it doesn't appear to be possible.

目前,我在 viewDidLoad 方法中手动分配这些(navigationItem和toolbarItems),或者直接在MainWindow.xib中定义它们,以便在应用初始化时加载。

Currently, I'm assigning these (navigationItem and toolbarItems) manually in the viewDidLoad method, or define them in the MainWindow.xib directly to be loaded when the app initializes.

任何想法?

我想我会尝试用图片解释。这是主窗口的Interface Builder,就像从向导中创建基于导航的项目一样。为了清楚起见,我添加了一个工具栏项目。您可以看到导航控制器,工具栏和导航栏以及根视图控制器。

I guess I'll try to explain with a picture. This is the Interface Builder of the main window, pretty much as it comes out of the wizard to create a navigation based project. I've added a toolbar item for clarity though. You can see the navigation controller, with a toolbar and a navigation bar, and the root view controller.

IB截图http://img526.imageshack.us/img526/3507/rootviewcontroller.png

基本上,根视图控制器有一个条形按钮项和一个导航项,如您所见。问题是,它还有一个与它关联的nib,当它被加载时将实例化一个视图,并将它分配给控制器的视图出口(在该nib中是File的所有者,类型为RootViewController,应该是)。

Basically, the Root View Controller has a bar button item and a navigation item as you can see. The thing is, it's also got a nib associated with it, which, when loaded will instantiate a view, and assign it to the view outlet of the controller (which in that nib is File's Owner, of type RootViewController, as should be).

如何将工具栏项和导航项放到另一个nib,RootViewController.nib中,以便我可以在这里删除它们。 RootViewController.nib将其他所有内容添加到Root View Controller中,为什么不将这些项添加?

How can I get the toolbar item, and the navigation item, into the other nib, the RootViewController.nib so I can remove them here. The RootViewController.nib adds everything else to the Root View Controller, why not these items?

这样做的背景是我想简单地实例化RootViewController,用它初始化它自己的nib(即initWithNibName:上面显示的nil),并将其推送到导航控制器,而不必在编码中添加导航/工具栏项(就像我现在这样做)。

The background for this is that I want to simply instantiate RootViewController, initialize it with its own nib (i.e. initWithNibName:nil shown above), and push it onto the navigation controller, without having to add the navigation/toolbar items in coding (as I do it now).

推荐答案

首先,你提出问题的方式在这里有点令人困惑,但我想我明白了。

First off, the way you've worded your question is a bit confusing here, but I think I understand.

你在这里有几个选择。如果要设计工具栏,只需在要加载的视图中添加一个工具栏,然后在Interface Builder中将各种按钮和分隔符拖到其上。然后在该视图的视图控制器中创建IBActions,并将工具栏项目中的连接拖动到各种操作。但是,由于您正在使用导航控制器,因此当您选择UINavigationController时(IB检查器中的属性选项卡),您将需要隐藏默认情况下通过取消选中MainWindow.xib中显示工具栏框的工具栏。

You've got a couple options here. If you want to design your toolbar, just add one to the view you are loading and drag the various buttons and separators onto it in Interface Builder. Then create IBActions in that view's view controller and drag connections from your toolbar items to the various actions. Since you are using a Navigation controller, though, you will want to hide the toolbar you get by default by unchecking the "Shows Toolbar" box in your MainWindow.xib when the UINavigationController is selected (Attributes tab in the IB inspector).

alt text http://cimgf.com/files /toolbarthing.png

或者,您可以通过调用[self setToolbarItems:items]在viewDidLoad方法中以编程方式添加工具栏项;其中items是工具栏项的NSArray。

Alternatively, you can just add toolbar items programmatically in the viewDidLoad method by calling [self setToolbarItems:items]; where items is an NSArray of toolbar items.

我真的没有办法让导航控制器使用你的自定义工具栏。只需隐藏主要的一个并使用您的自定义。

Really there is no way that I'm aware of to cause the navigation controller to use your custom toolbar. Just hide the main one and use your custom one.

这篇关于子笔尖中的工具栏项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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