Loading a subview from a nib file in interface builder?

It sounds like you have a single view in your nib file, and you want to be able to load an instance of that view at various places in your app.

It sounds like you have a single view in your nib file, and you want to be able to load an instance of that view at various places in your app. Here's whatcha do: First, in the nib file, change the File's Owner class to UIViewController, and set your custom view as the view property of the File's Owner. Then, in the view controller where you want to use an instance of your custom view, do the following: UIViewController *vc = UIViewController alloc initWithNibName:@"YourCustomNib" bundle:nil; UIView *yourCustomView = vc.

View; vc release; I know that seems kind of hacky, but last I heard that's actually one of the "right" ways of loading a single view from a nib. I use this method when I have custom tableview cells in the nib.

The only thing in my nib file is a toolbar with buttons. I made that the view controller's view. Then in the nib I need to include this in I had an empty view that I'm holding a reference to.

I allocated the view controller with the nib name as above and set self. Toolbar to the custom toolbar's view. It doesn't show up.

This is in viewDidLoad. – btate May 12 at 18:47 I got this working by adding a self. View addSubview: yourCustomView; to it.

Which means I can't count on Interface builder for the frame. Fortunately this is a toolbar that is always going to be at 0,0. So no big deal.

– btate May 12 at 20:41 I think I know what you mean…you can't really reference the toolbar view from another nib. You have to insert it in code. I usually do the same thing: use a placeholder view with the correct frame and then use that in the viewController to position the custom view.

– CharlieMezak May 13 at 15:16.

If yes, then you can load it independently anytime with NSArray *arr = NSBundle mainBundle loadNibnamed:@"customToolBarNibName" owner:... options:...; UIView *rootView = arr objectAtIndex: 0.

The toolbar is built out in a separate nib file. The toolbar class is CustomUIToolbar. All the buttons are connected to outlets CustomUIToolbar class.

And I have a delegate protocol for any view controller using the toolbar. Ideally I would like this to be an Interface Builder plugin, which apparently are no longer supported. I want to be able to put this toolbar into another view in Interface builder so I can keep track of the design.

– btate May 12 at 18:18 This works great, except for some reason in spite of the frame saying frame = (0 0; 1024 54);, the toolbar fills the screen. Here's the NSLog output of the object. > – btate May 12 at 19:48.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions