简体   繁体   English

在iPhone的表格视图中将数组从下载的内容保存到PList

[英]Saving Array to PList from downloaded content in table view on iPhone

I copied these posts from a forum where I posted recently, but got no reply. 我从最近发布的论坛中复制了这些帖子,但没有得到回复。

I have the base for my code all setup, it is a drill down table with navigation controller which loads data into a nsmutabledictionary from a plist with some empty values, on purpose. 我为所有代码设置了基础,它是一个带有导航控制器的向下钻取表,用于将数据从带有一些空值的plist加载到nsmutabledictionary中。 On command the app then downloads information which is then set, setValue, in NSMutableArray. 然后,根据命令,应用程序将在NSMutableArray中下载设置后的信息setValue。 The issue is that this NSMutableArray is 3 levels down from the root of the plist. 问题在于此NSMutableArray比plist的根目录低3级。 I am looking for a way to replace the array in the plist which is loaded and saved in the appdelegate. 我正在寻找一种方法来替换已加载并保存在appdelegate中的plist中的数组。 How do I this? 我该怎么办? Help is much appreciated. 非常感谢您的帮助。

So that probably didn't make much sense. 因此,这可能没有多大意义。 In the AppDelegate it loads a plist file into an NSMutableDictionary. 在AppDelegate中,它将plist文件加载到NSMutableDictionary中。 The plist is like this: plist是这样的:

Root
>Title(String) >标题(字符串)
>Rows(Array) >行(数组)
>>Item 1(Dictionary) >>项目1(字典)
>>>Title(String) >>>标题(字符串)
>>>ID(String) >>> ID(字符串)
>>>ItemList(Array) >>> ItemList(数组)
>>>>Item 1(Dictionary) >>>>项目1(字典)
>>>>>Title(String) >>>>>标题(字符串)
>>>>>ID(String) >>>>> ID(字符串)
>>>>>Value(String)-----------Empty Value which is Downloaded >>>>> Value(String)-----------已下载的空值
>>>>Item 2(Dictionary) >>>>项目2(字典)
>>>>Item 3(Dictionary) >>>>项目3(字典)
>>>>Item 4(Dictionary) >>>>项目4(字典)
>>Item 2(Array) >>项目2(阵列)
>>Item 3(Array) >>项目3(阵列)
>>Item 4(Array) >>项目4(阵列)

The Rows array is sent to the RootViewController. Rows数组被发送到RootViewController。 When one of these items is selected from the TableView and new instance is created with the table data source set to the ItemList of that selected item. 当从TableView中选择这些项目之一并创建新实例时,表数据源设置为该选定项目的ItemList。 When the user presses a button it downloads the values and using [setValue: forKey:@"Value"] the values are set in the array. 当用户按下按钮时,它将下载值,并使用[setValue:forKey:@“ Value”]在数组中设置值。 Here is where it gets lost. 这是它迷路的地方。 I need to now set this ItemList array back into the main Root dictionary and then that Root dictionary sent back to the AppDelegate, so that on applicationWillTerminate [self.data writeToFile:] can be called and the downloaded information does not need to be downloaded the next time. 现在,我需要将此ItemList数组设置回主Root字典,然后将该Root字典发送回AppDelegate,以便可以在applicationWillTerminate [self.data writeToFile:]上调用,而无需下载已下载的信息。下次。

I'm not totally sure I understanad what your problem is. 我不太确定我了解您的问题是什么。 Once you've got the new value populated into the array, you just need to use setObject:forKey: on the dictionary to replace the old array. 将新值填充到数组后,只需在字典上使用setObject:forKey:来替换旧数组。

If you're having trouble getting a reference to the app delegate, you can use [[UIApplication sharedApplication] delegate] 如果您在获取对应用程序委托的引用时遇到麻烦,则可以使用[[UIApplication sharedApplication]委托]

if the problem is that your dictionaries and arrays are nested such that you need to change more than one object to set the value, consider using mutableCopy to produce mutable arrays and dictionaries from the plist on load. 如果问题是字典和数组嵌套,因此您需要更改多个对象来设置值,请考虑使用mutableCopy在加载时从plist生成可变数组和字典。 Alternatively, maybe think about using a mire-sophisticated data representation, rather than reading and writing plist format. 或者,可以考虑使用复杂的数据表示形式,而不是读写plist格式。

我相信我可能必须使用forKeyPath

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

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