0

I'm totally lost with superview, loadView(), viewDidLoad(), viewWillAppear().

Eventually, I want to set my controller's frame to superview's bounds and utilize [self.view bounds] at my viewDidLoad(). (maybe this is impossible?)

here's the code snippet that gives me grief..

// add the controller's view to the scroll view
if (nil == controller.view.superview) {
CGRect frame = scrollView.frame;
    frame.origin.x = frame.size.width * page;
    frame.origin.y = 0;
    controller.view.frame = frame;
    [scrollView addSubview:controller.view];
    // I'd like to set controller.view 's frame using superview(scrollView here).
}

Apparently, nil == controller.view.superview calls the controller's viewDidLoad.

I used to access [self.view bounds] and use it inside my viewDidLoad
Since I want to set view's frame after adding it to superview, I guess I need to move the codes that utilizes [self.view bounds] to somewhere else.
What is the good place to move to? Or Is there better approach?

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
eugene
  • 39,839
  • 68
  • 255
  • 489

2 Answers2

0

The first call to controller.view and self.view automatically triggers the view loading mechanism and the viewDidLoad notification for each view controller (I'm assuming self is a different view controller). Thus the viewDidLoad methods for each controller will be called at the beginning of this code snippet.

(loadView is a method for you to manually override the view loading process. You shouldn't call it directly)

grahamparks
  • 16,130
  • 5
  • 49
  • 43
  • ah thanks, should have been controller.view, i messed that up. i've edited my question. in short can I set a view's frame using it's superview and use [self.view bounds] by the time viewDidLoad gets called? – eugene Nov 09 '10 at 11:17
0

I'll summarize the problem and my solution.

The problem is , in essence, that the order of two function calls: viewDidLoad and addSubview can not be switched.

What I want is,
set the frame of child according to superview which could only be done after addSubview.
But at the same time, upon viewDidLoad, I have the proper [self.view bounds].

Since viewDidLoad would have to be called before addSubview, viewDidLoad wouldn't be able to have the correct [self.view bounds] info.

Solution, I declared a superViewBounds variable and set them after allocing the view controller but before creating the view. And used the bounds variable inside viewDidLoad.

One thing remains, I still don't know how I could get the main view(I think it's called navigation view) bounds/frame info of navigationViewController.

Hope it helps, and hope someone post a better solution if there is.

eugene
  • 39,839
  • 68
  • 255
  • 489