简体   繁体   English

何时加载UITableView的数据? 什么时候tableview调用其委托方法。 查看后会出现吗?

[英]When UITableView's data is loaded? What's time tableview call its delegate methods. After viewWillAppear?

I am wondering when UITableview 's data is loaded. 我想知道何时加载UITableview的数据。

I mean, when I create a UITableView , then normally I will set its datasource and delegate. 我的意思是,当我创建UITableView ,通常将设置其数据源和委托。 After that, this tableview will be added as a subview. 之后,此表视图将添加为子视图。

However, If I don't call reload method, I don't know when the tableview know it needs to ask its delegates and show the data. 但是,如果我不调用reload方法,则不知道何时该tableview知道它需要询问其委托并显示数据。 In another word, since a view has no viewWillAppear methods, what's the exact time that a tableview ask its delegate and show the data? 换句话说,由于视图没有viewWillAppear方法,表视图询问其委托并显示数据的确切时间是什么?

I've tried some what: 我尝试了一些:

In viewDidLoad , I create a tableview, added it as subview, but not setting its delegates. viewDidLoad ,我创建一个表视图,将其添加为子视图,但未设置其委托。 Obviously, the data is not loaded. 显然,没有加载数据。

Then I set its delegate once I tap a button, its data is not loaded. 然后,一旦我点击一个按钮,就不会设置其数据,然后设置其委托。

But when the tableview's controller's viewWillAppear is called again (when the controller disappears and appears again), the data is loaded. 但是,当再次调用表视图的控制器的viewWillAppear时(当控制器消失并再次出现时),将加载数据。

There is no universal set time, because a UITableView's display data is in cells, and the cells are dynamically loaded. 没有通用的设置时间,因为UITableView的显示数据位于单元格中,并且单元格是动态加载的。 (also probably reused) You can call reload, but that just instructs the table to refetch the data on visible cells. (也可能被重用),您可以调用reload,但这只是指示表重新获取可见单元格上的数据。 The question remains: why do you need to know? 问题仍然存在:您为什么需要知道? If you need to intercept the data before it's loaded into a cell, do it in cellForRowAtIndexPath, where you're supposed to stuff the data into the cell. 如果需要在将数据加载到单元中之前对其进行拦截,请在cellForRowAtIndexPath中进行操作,在该处应将数据填充到单元中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM