开发者

How can I add viewController as subview? [duplicate]

开发者 https://www.devze.com 2023-03-26 09:03 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: Create a UIViewController that contain a UIViewController
This question already has answers here: Closed 10 years ago.

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.

  1. Create a UIView with the frame size that you want.

    UIView *testView; // alloc it and set frame size

  2. Add viewController.view as a subview to the testView.

  3. Add the testView with that frame size in mind and add that as a subview to self.view


try:

[currentView setNeedsDisplay];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号