我之前提过这个问题,我认为我的问题不正确,所以我会更清楚。另一次,答案非常好,虽然有用。我想在我的IOS Xcode中知道...我有一个Master / Detail View模板。我正在使用捆绑包中的Plist加载主表视图,但我正在更新文档文件夹中的Plist ...如何在捆绑包中反映这些更新,以及如何刷新屏幕。如果可以,请告知。先感谢您。 的问候,
这是我的代码加载主表...做任何看起来不正确:我从Documents文件夹加载...但我没有从文档中获取所有记录:
NSLog(@"loading data");
self.navigationItem.title=@"Accounts";
// NSString *accountFile = [[NSBundle mainBundle] pathForResource:@"Accounts2" ofType:@"plist"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];
NSString *plistPath = [documentPath stringByAppendingPathComponent:@"Accounts2.plist"];
accounts = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
account = [accounts objectForKey:@"Account"];
number = [accounts objectForKey:@"Number"];
dueDay = [accounts objectForKey:@"DayDue"];
minAmount = [accounts objectForKey:@"MinAmount"];
balance = [accounts objectForKey:@"Balance"];
NSLog(@"data loaded");
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
答案 0 :(得分:0)
您无法更新应用包中的任何内容。它是只读的(至少在真实的iOS设备上)。
您必须从可写位置(例如Documents
文件夹)读取和写入plist文件。第一次尝试访问该文件时,它将不存在。解决方案是从应用程序包中复制初始文件。从那时起,您只能在Documents
中读取/写入副本。