iPhone长列表 [英] iPhone long plist

查看:92
本文介绍了iPhone长列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些要添加到我的应用程序中的数据...大约650个类别(包括名称和ID号),每个类别平均包含85个项目(每个都有名称/ID号).

iPhone是否会支持这么大的列表?我想首先显示的类别在一个UITableView,当一类是选择我要显示所有相关的项目.有这么大的列表,我不确定在加载项目时iPhone是否会滞后.超过51,000行似乎...可能.

原始文本文件为2MB

解决方案

plist的长度可以是任意的.但是,带有2 MB文本数据的列表确实是个坏主意.即使在台式机上,Apple也只建议使用最大大小为数百KB的文件夹:

http://developer.apple.com/mac/library/documentation/cocoa/conceptual/propertylists/AboutPropertyLists/AboutPropertyLists.html#//apple_ref/doc/uid/10000048i-CH3-54402

原因是必须首先将plists完全反序列化到内存中,然后才能从plist访问单个元素.这对于小型的上位者是方便的,但是对于大型的上位者而言,在空间和时间上的效率非常低.

您应该将数据加载到数据库中.如果操作正确,数据库将只带入您需要的部分数据集,而不是整个数据集.

I have some data i want to add in to my app...about 650 categories (includes a name + id number), each with an average of 85 items (each with a name/id number).

Will the iPhone support such a large plist? I want to first display the categories in a UITableView, when a category is selected I want to display all of the associated items. Having such a large plist, im not sure if the iPhone will lag when loading the items. At over 51,000 lines it seems like...it might.

EDIT: The raw text file is 2MB

解决方案

A plist can be of arbitrary length. But a plist with 2 MB of text data is a really bad idea. Even on the desktop, Apple only recommends plists with a maximum size of a couple hundred KB:

http://developer.apple.com/mac/library/documentation/cocoa/conceptual/propertylists/AboutPropertyLists/AboutPropertyLists.html#//apple_ref/doc/uid/10000048i-CH3-54402

The reason is plists must be deserialized entirely into memory before you can access a single element from the plist. This is convenient for small plists, but extraordinarily inefficient in space and time for large plists.

You should be loading your data into a database. If you do it properly, a database will only bring in the portion of the data set you need, rather than the entire data set.

这篇关于iPhone长列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆