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

发布于 2024-07-29 17:31:45 字数 1158 浏览 2 评论 0原文

我从最近发帖的论坛复制了这些帖子,但没有得到回复。

我的代码有所有设置的基础,它是一个带有导航控制器的向下钻取表,它有意将数据从带有一些空值的 plist 加载到 nsmutabledictionary 中。 然后,应用程序根据命令下载信息,然后在 NSMutableArray 中设置 setValue。 问题是这个 NSMutableArray 距离 plist 根部向下 3 层。 我正在寻找一种方法来替换 plist 中加载并保存在 appdelegate 中的数组。 我该怎么办? 非常感谢您的帮助。

所以这可能没有多大意义。 在 AppDelegate 中,它将 plist 文件加载到 NSMutableDictionary 中。 plist是这样的:

Root
>标题(字符串)
>行(数组)
>>第 1 项(字典)
>> 标题(字符串)
>>ID(字符串)
>>> 项目列表(数组)
>>>>第 1 项(字典)
>>>>>标题(字符串)
>>>ID(字符串)
>>>>>Value(String)----------下载的空值
>>>>第 2 项(字典)
>>>第3项(字典)
>>>>第 4 项(字典)
>>第 2 项(数组)
>>第 3 项(数组)
>> 第 4 项(数组)

Rows 数组被发送到 RootViewController。 当从 TableView 中选择这些项目之一时,将创建新实例,并将表数据源设置为该所选项目的 ItemList。 当用户按下按钮时,它会下载值并使用 [setValue: forKey:@"Value"] 将值设置在数组中。 这就是它丢失的地方。 我现在需要将此 ItemList 数组设置回主 Root 字典,然后将该 Root 字典发送回 AppDelegate,以便在 applicationWillTerminate [self.data writeToFile:] 上可以调用,并且不需要下载下载的信息下次。

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. On command the app then downloads information which is then set, setValue, in NSMutableArray. The issue is that this NSMutableArray is 3 levels down from the root of the plist. I am looking for a way to replace the array in the plist which is loaded and saved in the appdelegate. 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. The plist is like this:

Root
>Title(String)
>Rows(Array)
>>Item 1(Dictionary)
>>>Title(String)
>>>ID(String)
>>>ItemList(Array)
>>>>Item 1(Dictionary)
>>>>>Title(String)
>>>>>ID(String)
>>>>>Value(String)-----------Empty Value which is Downloaded
>>>>Item 2(Dictionary)
>>>>Item 3(Dictionary)
>>>>Item 4(Dictionary)
>>Item 2(Array)
>>Item 3(Array)
>>Item 4(Array)

The Rows array is sent to the 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. When the user presses a button it downloads the values and using [setValue: forKey:@"Value"] the values are set in the array. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀念你的温柔 2024-08-05 17:31:45

我不完全确定我理解你的问题是什么。 将新值填充到数组中后,您只需在字典上使用 setObject:forKey: 即可替换旧数组。

如果您在获取对应用程序委托的引用时遇到问题,

如果问题是您的字典和数组是嵌套的,因此您需要更改多个对象来设置值,则 可以使用 [[UIApplication sharedApplication] delegate],考虑使用 mutableCopy 在加载时从 plist 生成可变数组和字典。 或者,也许考虑使用复杂的数据表示,而不是读写 plist 格式。

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.

If you're having trouble getting a reference to the app delegate, you can use [[UIApplication sharedApplication] delegate]

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. Alternatively, maybe think about using a mire-sophisticated data representation, rather than reading and writing plist format.

彼岸花似海 2024-08-05 17:31:45

我相信我可能必须使用 forKeyPath

I believe I might have to use forKeyPath

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文