1

So I have a UIViewController inside a UIViewController and inside a UIViewController and I am trying to adjust its frame. However when I call setFrame:, it calls the viewDidLoad of that particular view controller I am trying to adjust the frame. However at that time the frameSize isn't the one that I set. In this viewDidLoad I am also calling a private method called loadDataFromServer, which pulls in data from memory first and then make a call to the server. Because it's loading data from memory, it does it really quick, basically before viewDidLoad is finished and therefore the frame size hasn't been adjusted yet. So I see the view with the wrong size/layout first and then it adjusts after getting data from the server, which at this point viewDidLoad is finished and the frame is adjusted well.

If I move the loadDataFromServer call to viewDidAppear then it all looks fine. The thing is that I am not sure when viewDidAppear is called. Is it called after viewDidLoad once? Or is it called after viewWillAppear? Any idea/work around for this?

    ContainerViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContainerViewController"];
    vc.delegate = self;

    UINavigationController *newsfeedNavController = [[UINavigationController alloc] initWithRootViewController:vc];

    [self addChildViewController:newsfeedNavController];
    newsfeedNavController.view.frame = CGRectMake(0, 0, self.view.frameWidth, self.view.frameHeight);
    [self.view addSubview:newsfeedNavController.view];
    [newsfeedNavController didMoveToParentViewController:self];
    [newsfeedNavController release];
David Berry
  • 40,941
  • 12
  • 84
  • 95
xonegirlz
  • 8,889
  • 19
  • 69
  • 127
  • because I need some logic in it and it's just not a view. – xonegirlz Jul 06 '12 at 16:30
  • What specifically are you trying to accomplish ? – Aleksander Azizi Jul 06 '12 at 16:32
  • I have a containerviewcontroller and a feedsviewcontroller, this feedsviewcontroller has some logic in it and is used as a subview of other viewcontrollers. – xonegirlz Jul 06 '12 at 16:37
  • viewDidAppear is called after the main view of the particular view controller has been added to the view hierarchy of the parent view controller. – timthetoolman Jul 06 '12 at 16:48
  • Use -viewWillLayoutSubviews on iOS 5 or -viewDidAppear: if you have to support earlier versions of iOS. Your view controller's view will have the correct bounds when either of these methods are called. – Jason Coco Jul 06 '12 at 16:51
  • possible duplicate of [Why am I having to manually set my view's frame in viewDidLoad?](http://stackoverflow.com/questions/6757018/why-am-i-having-to-manually-set-my-views-frame-in-viewdidload) – Eliza Wilson May 23 '14 at 21:29

0 Answers0