views:

162

answers:

1

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.

+1  A: 

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.

willcodejavaforfood
That's definitely a workable option. I would only be hesitant to use this because it would mean hardcoding frame sizes into my view controller based on the presence of tabBarController and navigationController - what happens when I want to port this to iPad or another device with a different screen size?
pix0r
I think you are worrying too much about 'other' devices here really. So far there is only one other device and that is the iPad which will have a much larger screen so you would probably need to redesign the views anyway. :)
willcodejavaforfood
Each of those controllers has properties to get to the tabBar and/or navigationBar, which you can get the sizes from to deduce the proper remaining size for your screen...
Kendall Helmstetter Gelner
@Kendall - That should work for pix0r :) Well spotted mate!
willcodejavaforfood
+1 Kendall (also +1 OP), that sounds like the best option. Thanks!
pix0r