我无法理解何时创建表视图。
我有两个标签视图。在第二个选项卡视图中,我有一个datasource
遵守表格视图协议的表格。
Whenever the second tab is selected /clicked the tables datasource method
numberOfRowsInTableView
is called on every click.
我正在使用 xcode 4.2。
那是因为每个选项卡视图在选择选项卡时都会重新创建其视图?
我在这里错过了什么吗?
我无法理解何时创建表视图。
我有两个标签视图。在第二个选项卡视图中,我有一个datasource
遵守表格视图协议的表格。
Whenever the second tab is selected /clicked the tables datasource method
numberOfRowsInTableView
is called on every click.
我正在使用 xcode 4.2。
那是因为每个选项卡视图在选择选项卡时都会重新创建其视图?
我在这里错过了什么吗?
I have trouble in understanding when does table View gets created.
If it's in a nib, it's created when you load the nib.
Actually, it depends on what you mean by “created”. You created it when you put the table view into the nib in Xcode. When you save, Xcode archives that object into the nib.
Then, at run time, when your app loads the nib, Cocoa unarchives the table view (along with everything else in the nib). That unarchiving is the moment of “creation” after which the table view exists in your app.
Whenever the second tab is selected /clicked the tables datasource method
numberOfRowsInTableView
is called on every click.
The table view already exists by then. It sends that message (among other data source messages) whenever it becomes visible, whether or not it's becoming visible for the first time.
If you switch to a different tab, the table view has no reason to show anything, so it won't bother following updates to the model.
If you then switch back, making the table view visible, now the table view has a reason to show something, so it needs to know if anything has changed so it can show the model's current state. So, it rechecks its data source at that time.
这取决于 TableView 的内容是动态的还是静态的。如果它是动态的,它是在方法tableView:cellForRowAtIndexPath:
调用时创建的。如果内容是静态的,它是在加载视图时创建的。请注意,tableView:cellForRowAtIndexPath:
调用不止一次,它被称为数据源项的计数。希望有帮助:)