简体   繁体   English

提高uitableview的性能

[英]increasing the performance of uitableview

I have this application that I am letting the user set up a search query based of values selected by them from a bunch of xml data that will then be used to search the database for stuff. 我有这个应用程序,我让用户根据他们从一堆xml数据中选择的值来设置搜索查询,然后将这些数据用于搜索数据库中的内容。

At the moment I have 3 cells that can accept search parameters for the query, each cell loads its data onto the same uitableview so I have to do abit of fudging with my if statements to make sure everything works correctly for the correct dataset. 目前,我有3个可以接受查询搜索参数的单元格,每个单元格都将其数据加载到同一uitableview中,因此我必须对if语句进行一些摸索,以确保所有正确的数据集都能正常工作。

the first cell allows the user to pick a motorbike manufacture, all of the manufactures are listed on the table view. 第一个单元格允许用户选择摩托车制造商,所有制造商均列在表格视图中。 the xml that is being loaded has a key value that is related to the second list which lists the model of every manfacture. 正在加载的xml具有与第二个列表相关的键值,该列表列出了每个制造厂的模型。 I am wanting to set up the list of manufactures based of the manufacture selection as soon as the user selectes a tableviewcell. 我想在用户选择tableviewcell后立即基于制造商选择设置制造商列表。

so that when the user is back to the main view then selects the second cell the (dictionary) that i have created loads really fast. 因此,当用户返回主视图时,然后选择第二个单元格,我创建的(字典)加载得非常快。

At the moment everything is done each time the subview is loaded.. so because my manufacture list is so big, when the user selects the manufacture they would like to search when the come back to the subview with the manufactre selected the id has to be compaired to every single model of every single manufacture to get the list to display which takes a very long time. 目前,每次加载子视图时,所有操作都完成了..因此,由于我的制造商列表很大,当用户选择制造商时,他们想在返回带有所选制造商的子视图的子视图时进行搜索。适应每个制造商的每个模型以显示要花费很长时间的列表。

I would like to know how you would attempt something like this. 我想知道您将如何尝试这样的事情。 below is a flow chart of how I am thinking to do it. 以下是我如何考虑的流程图。 I would like some comments/suggestions on if you think im doing it right or not and also how to even attempt this. 我想对您是否认为自己做对或不做以及如何尝试这样做提出一些意见/建议。 在此处输入图片说明

any help would be greatly appreciated (if you cannot read the text in the image you can right click save to desktop and its alot bigger) 任何帮助将不胜感激(如果您无法阅读图像中的文本,则可以右键单击“保存到桌面”,然后单击“保存”)

To do this properly you probably want to use some sort of data structure in your application which allows fast querying rather than doing multiple parses of your xml input file. 为了正确执行此操作,您可能希望在应用程序中使用某种数据结构,该结构允许快速查询,而不是对xml输入文件进行多次解析。

For a simple "first-cut" solution you could parse the XML file into an NSDictionary and query this for Manufacturer -> Model relationships. 对于简单的“第一手”解决方案,您可以将XML文件解析为NSDictionary,并向其查询制造商->模型关系。 You can build the NSDictionary once off the XML file then persist the result somewhere and searching will be much faster than looking through the XML each time. 您可以从XML文件中构建一次NSDictionary,然后将结果保存在某个位置,并且比每次浏览XML都快得多。

For something more robust it'd be worth looking into using CoreData to store your Manufacturer -> Model relationship. 对于更强大的功能,值得考虑使用CoreData存储您的Manufacturer-> Model关系。 This would take more code on your behalf but would give you a much nicer object model. 这将代表您使用更多代码,但会为您提供更好的对象模型。

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

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