IPhone : View property on a Xib, is it special?
I can't believe I am stuck on thi开发者_StackOverflows 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.
精彩评论