问题
I created UITabBarController with each tab contain UINavigationController and set rootviewcontroller in this UINavigationController, all of this is done in interface builder. In viewDidLoad I try to get frame size from view, but when I reference view it return null. Have anyone experienced this before.
All IBoutlet are properly connected.
回答1:
viewDidLoad returning a nil view if the view is connected in your .xib could mean:
For programmatic initialisation (custom controllers):
- You forgot to call
initWithNibName:bundle:on the view controller class altogether (you may have calledinitor something instead). - You've overridden the
loadViewmethod in your view controller class, but it doesn't set theview.
For all controllers:
- An outlet connection hasn't been made correctly.
- You have accidentally released the view or view controller before showing it.
- The
nibNameparameter was not properly specified when initialising the view (the nib could not be found or one without a view was found.. though this should also throw an exception). - There wasn't enough memory to allocate the
view(the app would likely have been terminated by that point though).
I'd recommend you try doing frame size calculations in viewWillAppear: instead and see if the view is still nil at that point.
来源:https://stackoverflow.com/questions/7266177/view-is-null-in-viewdidload