【发布时间】:2012-06-14 20:38:50
【问题描述】:
我将 plist 加载到 NSArry,过滤该数组以捕获我需要的数据,然后将数据呈现给 UITableView。这很好用。
编辑:
我正在处理字典数组。 Plist 充满了字典数组。
这就是我的工作:
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"/data.plist"];
//array is filled with dictionaries
array = [NSMutableArray arrayWithContentsOfFile:filePath];
//filter the array to catch appropriate data (there are maybe 10 objects):
self.arrayFiltered = [NSMutableArray arrayWithCapacity:[array count]];
NSDictionary *dict;
for (dict in array)
if ([[dict valueForKey:@"globalKey"] isEqualToNumber:[NSNumber numberWithInt:year]])
[arrayFiltrirani addObject:dict];
现在我用 arrayFiltered 中的数据填充 tableView。现在我想从 tableView 和 arrayFiltered 中删除一行。
[self.arrayFiltrirani removeObjectAtIndex:indexPath.row];
但是!!!如何更新原始数组并将其保存到 plist?
【问题讨论】:
-
你的实际意图是什么?您提供的代码与您所说的完全一样。它需要一个数组并将其转换为 .plist。您要保留现有文件内容以及新文件内容吗?那是 NSDictionary 更适合的东西。
-
当我将过滤后的数组保存到 plist 时,之前的所有数据都会被覆盖,现在 plist 中只有来自 arrayFiltered 的数据。
标签: iphone uitableview nsarray plist