loadView vs viewDidLoad
来源:互联网 发布:sql ndf 数据库还原 编辑:程序博客网 时间:2024/05/29 06:42
The Problem:
I was getting a white screen with no data in a UITableView on it in the iPhone simulator.
The Solution:
I had my initialization code for the array in the the "loadView" method and not the "viewDidLoad" method
Explanation:
Don't read self.view in -loadView. Only set it, don't get it.The self.view property accessor calls -loadView if the view isn't currently loaded. There's your infinite recursion. I'm guessing UITableView calls a View [pretty good guess since "view" is in the name. :)] which in turn caused my recursion.
This was a stupid little error that caused me about 30 minutes of my life due to the fact I didn't get any build errors. A simple copy and paste moved me forward.
Update: I think it might be important to distinguish the differece between loadView and viewDidLoad. (below)
loadView is the method in UIViewController that will actually load up the view and assign it to the "view" property. This is also the location that a subclass of UIViewController would override if you wanted to programatically set up the "view" property.viewDidLoad is the method that is called once the view has been loaded. This is called after loadView is called. It is a place where you can override and insert code that does further initial setup of the view once it has been loaded.
Don't read self.view in -loadView. Only set it, don't get it.
--前一陣我也經常犯了這個錯誤,導致死循環,因為只要一get view,而view又還沒創建,框架就會調用loadView來嘗試創建view
- loadView VS viewDidLoad
- loadView vs viewDidLoad
- loadView vs viewDidLoad
- loadView VS viewDidLoad
- loadView VS viewDidLoad
- loadView VS viewDidLoad
- viewDidLoad(), LoadView()
- loadView & viewDidLoad
- loadView viewdidload
- loadView & ViewDidLoad
- init/loadView/viewDidLoad/viewDidUnload
- awakeFromNib viewDidLoad initWithCoder loadView
- loadView,viewDidLoad,viewDidUnload
- loadView viewDidLoad viewDidUnload区别
- init/loadView/viewDidLoad/viewDidUnload
- loadView与viewDidLoad不同
- loadView与viewDidLoad不同
- loadView and viewDidLoad
- 写TextView的Selector了解到的android读取xml文件的几点规则
- JAVA设计模式之Singleton
- [转]ARM方案大汇总
- fedora14 root登录
- 过劳死,IT民工你伤不起
- loadView vs viewDidLoad
- poj 3077 递归
- 一次性读入文件全部内容
- 软件保护措施的研究
- 弄了个空间,买了个域名,装了个wordpress
- log2
- 五一前的反思
- 简单锁屏代码
- java se me ee 的基本概念