1
votes

I've got the following setup.

A pagingScrollViewController with a UIScrollView as it's view (self.view = scrollView). In that scrollView I add the view of a rootViewController as subview. The view of the rootViewController is an UIView on which I add one or the other view (depending on internal logic).

The UIScrollView is initialized with a frame equal to the applicationFrame, so 0, 20, 320 , 460. Which is fine because of the statusbar on top.

The problem comes when adding the rootViewController's view to the scrollview. In the creation process of the rootViewController it's view is setup in -loadView which is still commented out in my case. So the standard appel loadView is processed.

It gives me a view which also has a frame of 0, 20, 320, 460. Which is not as I would like to see it as now the View of the rootViewController is 40 pixels removed from the top of the actual iphone screen.

Now, this is of course easily fixed by manually setting the rootViewControllers view in -loadView or assigning it a frame where the y is set to 0 in -viewDidLoad;

But I cannot imaging that that is the way apple intended this to be done. I'm not using Interface builder, so maybe that's the problem, apple intends me to use IB, but im stubborn on that subject :)

Am I using viewControllers the wrong way? This seemed a nice way to split the logic of the scrollView away from the logic of the other view's.

What would be the correct way to add the view of a second UIViewController to the view of a first UIViewController. In which the first viewController.view receives a frame of 0, 20 , 320, 460. And de second controller.view a frame of 0, 0, 320, 460 (so basically the bounds of the first controller.view)

There's a lot of use of the word controller and view in there, hope the question is clear though.

1
how you are initializing rootViewController's view frame?Ravin
I'm not, that's the magic at work. If you don't override -loadView, a view is created for you by the system. Unfortunately with a frame of 0,20,320,460.DIJ
thats the answer itself. your rootViewController has frame 0,20,320,460 provided by the system. so when you add it on your view which is normal it will relatively lower with y=20.Ravin
Pay attention at: "In that scrollView I add the view of a rootViewController as subview". Apple states: only ONE view controller present for a displayed screen. If your pagingScrollView controller isn't owned by rootViewController you will get memory warning of level = 2.Stefan Ticu
@inovaction... thanks for the tip!DIJ

1 Answers

1
votes

To answer my own question...

Ravin was right. After reading up on the loadView method and apple's view controller programming guide I've come to the conclusion that this is the default behavior of the system. If you want anything else, override -loadView and do it yourself. Actually apple states that if you don't use an NIB, you SHOULD override -loadView to create at least a basic simple view.