views:

110

answers:

1

Hi,

I have a UIViewController* compViewController which switches between two copies of the same view (with small differences between the two views). Currently, both views come form the same xib file. The xib file contains two almost identical copies of the same view hierarchy. One of the copies, "the main one" is connected to the view outlet in the compViewController. The second view is connected to an auxView outlet in the compViewController. The view controller chooses to display one or the other view. Actually, this description is an oversimplification of the actual situation. In reality one of the two views is passed as the "overlayView" to a UIImagePickerController which is pushed as a modal controller by the compViewController.

This approach turns out to be a maintenance nightmare because any changes to one view need to be replicated on the other view in the nib.

One possible solution I'm thinking would be to remove one copy of the view hierarchy from the nib and then load the nib twice to obtain two copies of the view. Then make the necessary changes programmatically to one of them in the compViewController's viewDidLoad method before it gets passed as the overlay to the UIImagePickerController.

I'm using the loadNibNamed method in the UIKit extension category for NSBundle (I think this is an iPhone only category) which takes an owner. If the owner is the same ViewController then the resulting object is the same object, i.e. calling loadNibNamed twice for the sam xib with the same owner returns the same exact instance. I believe I need two separate instances, as in the past I tried passing the same instance of the view used by the compViewController to the ImagePicker and all kinds of bad things happened. I read then that you should never share UI objects between different UIViewContollers, at least not to ViewControllers that are both pushed into the same NavigationController.

Am I missing a better way of doing this?

Thank you very much in advance for any advice you might have for me.

A: 

My understanding was a nib was owned by a viewController and could only have one owner. I moved away from nibs and and started building everything in code. It takes a bit more work at the beginning but was more reusable and powerful as I was finding nibs limiting.

Rudiger