简体   繁体   中英

IPhone : View property on a Xib, is it special?

I can't believe I am stuck on this but here goes.

I have a viewController which I am trying to add to another viewController via the addsubview property (basic as) however I am not doing viewController.view but viewController.myView1.

I basically have 2 root views on the xib (both with outlets) however I don't want to wire up the view property of the xib because I want to choose which view to show.

I can't get it to appear! Is the view property some sort of special hook?

I can't see why addsubview:mysubview should not work?

Some examples seem to use 2 different xib's but that seems a overkill

Firstly, Apple say a viewcontroller should be used for a whole screen full of views - (but I guess iPad container views are different).

I guess you're wanting to only use one of the viewcontrollers at once. In which case you shouldn't be using subview - just create the viewcontroller programmatically, create the view, assign the view to the viewcontroller's view property and then add the viewcontroller to the window or navigation bar.

and, in your viewcontroller:

self = [super initWithNibName:nibOne bundle:nil];

might be what you want - it allows you to use multiple nibs with a single viewcontroller.

Can you NSLog your viewController.myView1 before add it as a subview? Is it nil or not?

If it's nil , try to add this line before your addSubview: method:

[viewController view];

Note: The viewController I am talking about is the same viewController which have two root views view and myView1 .

Your code should be good as this is fairly simple and I do it all the time. Just make sure your outlets are wired properly and that you are synthesizing them and that they are public in your header.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM