English 中文(简体)
Toolbar items in sub-nib
原标题:

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.

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.

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];

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.

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.

Any ideas?

Edit

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 Screenshot http://img526.imageshack.us/img526/3507/rootviewcontroller.png

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

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?

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.

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

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.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签