从Core data中显示大量数据。

时间:2022-05-25 01:03:43

I have such a task in front of me: there are more than 10,000 records in the database, I need to display them in the table view, but I can not take all 10,000 and store in the array how to organize the work, for example, when scrolling 100 records in a table view, Download the next 100 entries from the database.

我有这样一个任务在我面前:有超过10000条记录在数据库中,我需要显示在表视图,但是我不能把所有10000和存储数组中如何组织工作,例如,当滚动100条记录在表格视图,从数据库下载下一个100个条目。

I found things like fetchLimit and fetchOffset, but I still did not understand how to use them for my task.

我找到了fetchLimit和fetchOffset之类的东西,但是我仍然不知道如何使用它们来完成我的任务。

What would you tell me?

你能告诉我什么?

1 个解决方案

#1


3  

I believe if you are using Core Data and you need UITableView you should defiantly use NSFetched​Results​Controller.

我相信如果你在使用Core Data你需要UITableView你应该大胆地使用nsfetchedresultscontroller。

From Apple documentation.

从苹果公司文档。

You use a fetched results controller to efficiently manage the results returned from a Core Data fetch request to provide data for a UITable​View object.

您可以使用fetchedresultscontroller来有效地管理从核心数据获取请求返回的结果,从而为一个特定的视图对象提供数据。

By using of this approach you going to use by default Cache that will improve performance. Also with this you going to dynamically update UITableView when some of the records in Core Data will be changed or be added.

通过使用这种方法,您将使用默认缓存来提高性能。此外,当Core Data中的一些记录将被更改或添加时,您将动态更新UITableView。

Also to fetch data by portion you can modify NSFetchRequest and setfetchLimit for each request.

另外,要按部分获取数据,可以修改每个请求的NSFetchRequest和setfetchLimit。

Example of the simple NSFetched​Results​Controller implementation.

简单的nsfetchedresultscontroller实现示例。

#1


3  

I believe if you are using Core Data and you need UITableView you should defiantly use NSFetched​Results​Controller.

我相信如果你在使用Core Data你需要UITableView你应该大胆地使用nsfetchedresultscontroller。

From Apple documentation.

从苹果公司文档。

You use a fetched results controller to efficiently manage the results returned from a Core Data fetch request to provide data for a UITable​View object.

您可以使用fetchedresultscontroller来有效地管理从核心数据获取请求返回的结果,从而为一个特定的视图对象提供数据。

By using of this approach you going to use by default Cache that will improve performance. Also with this you going to dynamically update UITableView when some of the records in Core Data will be changed or be added.

通过使用这种方法,您将使用默认缓存来提高性能。此外,当Core Data中的一些记录将被更改或添加时,您将动态更新UITableView。

Also to fetch data by portion you can modify NSFetchRequest and setfetchLimit for each request.

另外,要按部分获取数据,可以修改每个请求的NSFetchRequest和setfetchLimit。

Example of the simple NSFetched​Results​Controller implementation.

简单的nsfetchedresultscontroller实现示例。