View is null in viewDidLoad

旧城冷巷雨未停 提交于 2019-12-02 10:58:00

问题


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 called init or something instead).
  • You've overridden the loadView method in your view controller class, but it doesn't set the view.

For all controllers:

  • An outlet connection hasn't been made correctly.
  • You have accidentally released the view or view controller before showing it.
  • The nibName parameter 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!