How can I add viewController as subview? [duplicate]
Possible Duplicate:
Create a UIViewController that contain a UIViewController
I have a parent view with many subview in different viewcontroller because a part of screen is same with every view, so i create only needed part of other screen in other view controller nib. Then i planed when a view need load i will just add it like subview and remove it switch to another screen it's just simple
viewController = []...
[self.view 开发者_开发技巧addSubview:viewController.view];
currentView = viewController.view;
currentView.setFrame :(aFrame); // to move to different part (all screen has a common part)
But my problem is new view is added to screen but it always stay at (0,0) no matter how frame i did set. But weird thing is if i tap at part of screen in new frame it will be behavior like view was moved there but screen not redraw.
What wrong? Please help
You said:
i create only need only need part of other screen in other view controller nib
I think that the problem could be related to the way the view is created in Interface Builder. Specifically, if you create a nib file and choose the "View" type, then a nib is created that contains a view with a fixed size (screen size).
So, my suggestion is trying and create a nib using the "Empty" template and then adding a UIView from the library. In this case, you will be allowed to set the view size (in the third pane of the Inspector). Possibly this will fix your problem.
Do this.
Create a UIView with the frame size that you want.
UIView *testView; // alloc it and set frame size
Add
viewController.view
as a subview to thetestView
.Add the
testView
with that frame size in mind and add that as a subview toself.view
try:
[currentView setNeedsDisplay];
精彩评论