0
votes

I have an WizardSequenceViewController with an IBOutlet WizardView *_wizardView. In many WizardSequenceViewController.xib file I have the view outlet connected to the File's Owner - WizardSequenceViewController. I have a subview of that view defined with the class attribute set to WizardView. I have connected that WizardView to the outlet in the File's Owner. Finally, in my WizardView.xib I have a UILabel that I have placed in the file to test if the view is being rendered. When I select the WizardSequenceViewController from my tab bar, I see the superview view but not the subview _wizardView. When I set a breakpoint in my -(id)initWithCoder method in my WizardView.m file I see it stop there, so I know that it is calling that initializer (and thus it should be using the xib to load that file). I have tried many iterations and variations to get this thing to work but I can't and I am going crazy. Does anybody have any ideas?

2
Have you tried initWithNibName:@"WizardView"?Wienke
@Wienke, why would I need to call that if I have set the outlet for _wizardView and I know it is calling the initWithCoder initializer for WizardView?tacos_tacos_tacos
I wasn't even aware that nibs were considered to have been encoded. I've always used the nibName when loading them. It was just an idea for a simple thing to try. Perhaps you could call initWithNibName from initWithCoder.Wienke
Actually, why not simply call a present method on the outlet?Wienke
Can you clarify by what you mean by a present method?tacos_tacos_tacos

2 Answers

0
votes

From Apple doc "View Controller Basics, About Custom View Controllers":

The one-to-one correspondence between a view controller and the views in its view hierarchy is the key design consideration. You should not use multiple custom view controllers to manage different portions of the same view hierarchy. Similarly, you should not use a single custom view controller object to manage multiple screens worth of content.

Note: If you want to divide a view hierarchy into multiple subareas and manage each one separately, use generic controller objects (custom objects descending from NSObject) instead of view controller objects to manage each subarea. Then use a single view controller object to manage the generic controller objects.

Maybe you can't do a view-and-subview outlet setup in a view controller. And I'm not sure assigning the subview outlet to a separate NSObject subclass would work either, because how would you present it? Could you write your subview programmatically, using initWithFrame and addSubview, instead of making it an outlet? Or, if you really want to set it up graphically, could you assign it to a separate view controller as owner? Then the top view controller will call presentModal on the sub view controller. Or, if all you need is a UILabel as a subview, just add the label to the main view?

0
votes

Even I faced a similar issue. But got it resolved by following steps given in the following link. Hope it helps. http://blog.yangmeyer.de/blog/2012/07/09/an-update-on-nested-nib-loading