2
votes

I'm having a problem getting my view to be sized properly when created via -loadView. It seems that my view frame is always (0, 0, 320, 460), even when the view/controller is nested inside a UINavigationController and/or UITabBarController. Is there a way to detect programmatically when my view controller is nested within these items, so that I can set the proper frame? My loadView is just setting up a nested UIScrollView that should match exactly the visible size on the screen (460px is too tall when there is a tab bar and nav bar visible).

The reason I'm not hardcoding these values is that I would like this view controller to be reusable and work in all scenarios.

2

2 Answers

2
votes

There are a few properties of in UIViewController that might be of interest here:

  • navigationController
  • tabBarController

If these are not nil you should be able to tell if you need to resize your view or not.

0
votes

Do not layout your views in loadView: or viewDidload: without a nib. Do it in viewWillAppear:, the main view's frame is properly at that time.