简体   繁体   English

基于另一个创建iOS plist

[英]Creating iOS plist based on another

I'm very new to iOS development and am having an issue. 我对iOS开发非常陌生,遇到了问题。 I have a plist that contains a lot of information for a bunch of different animals. 我有一个plist,其中包含许多有关一堆不同动物的信息。 The plist is an array of dictionaries, and each dictionary is an animal. plist是字典的数组,每个字典都是动物。 Each dictionary has a key called “type”, which is the type of animal (cat, dog, bird, etc). 每个字典都有一个称为“类型”的键,它是动物(猫,狗,鸟等)的类型。 I want my application to first display a table view that lists all of the possible types. 我希望我的应用程序首先显示一个列出所有可能类型的表视图。 When the user selects the type, they will then go to another table view that lists all of the animals of that selected type. 当用户选择类型时,他们将进入另一个表格视图,其中列出了该所选类型的所有动物。 They can then select that specific animal and another view will be displayed that has all the detailed information about that specific animal. 然后,他们可以选择该特定动物,然后将显示另一个视图,其中包含有关该特定动物的所有详细信息。 I suppose the best way to approach this is that when a user selects the “type” of animal, a new plist will be generated containing the directory entries from the original plist that have a “type” key that matches what the user selects. 我想最好的解决方法是,当用户选择动物的“类型”时,将生成一个新的plist,其中包含来自原始plist的目录条目,这些目录条目具有与用户选择的内容匹配的“ type”键。 How can I implement this? 我该如何实施? Would this logic be in the viewDidLoad method for the second table view? 第二个表视图的viewDidLoad方法中是否包含此逻辑? Once the plist is created that contains only the animals of interest, the cellForRowAtIndexPath method would display the list of animals? 创建仅包含感兴趣动物的plist后,cellForRowAtIndexPath方法将显示动物列表吗? Thanks for any assistance! 感谢您的协助! David 大卫

First: You shouldn't generate any new plists in this situation... If you want to store a list of dictionaries based on a query of your data, it should go into an NSMutableDictionary/NSDictionary. 第一:在这种情况下,您不应该生成任何新的plists。如果您要基于对数据的查询存储字典列表,则应将其放入NSMutableDictionary / NSDictionary。 Before creating each table, you should construct one of these dictionaries with the filtered data, and pass it to the table as the data source. 在创建每个表之前,应使用过滤后的数据构造其中一个字典,并将其作为数据源传递给表。

Second: I'd try using a database instead of a plist to make your queries a little easier to manage. 第二:我会尝试使用数据库而不是plist来简化查询的管理。

Third: Normalize your data as much as possible, hence, have a database table (or plist if you go that route) of "animal types," and a db table/plist of "animals" ... then reference the animal's type by id, instead of by name. 第三:尽可能规范化您的数据,因此,具有“动物类型”的数据库表(如果使用该路线,则为plist)和“动物”的db表/ plist ...然后通过引用动物的类型ID,而不是名称。 If you change that name in the future, you'll have a hell of a time trying to find every occurrence. 如果您将来更改该名称,那么将很难找到所有出现的名称。 In addition, it's less buggy that way; 另外,这样可以减少故障。 one accidental misspelling will leave you wondering why one animal is causing an error and the others aren't. 一种意外的拼写错误会让您想知道为什么一只动物引起了错误,而另一只却没有引起错误。

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

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