Objective c Xcode保存到Plist

Objective c Xcode保存到Plist,objective-c,plist,Objective C,Plist,您好,我已经设置了一个表视图来显示plist中的entires,并且有一个部分来向plist添加新数据,但是我无法保存数据。。。它存储良好,显示良好,但当我离开应用程序并重新加载新数据时,我就是这样保存的 - (IBAction) save: (id) sender { NSLog(@"%@", @"Save pressed!"); if (self.job != nil) { // We're working with an existing drink, so let's remo

您好,我已经设置了一个表视图来显示plist中的entires,并且有一个部分来向plist添加新数据,但是我无法保存数据。。。它存储良好,显示良好,但当我离开应用程序并重新加载新数据时,我就是这样保存的

- (IBAction) save: (id) sender {
NSLog(@"%@", @"Save pressed!");

if (self.job != nil) {
    // We're working with an existing drink, so let's remove
    // it from the array and just recreate it like we would a new
    // drink...
    [jobArray_ removeObject:self.job];
    self.job = nil; // This will release our reference and set the property to nil
}

// Create a new drink dictionary for the new values
NSMutableDictionary *newDrink = [[NSMutableDictionary alloc] init];
[newDrink setValue:self.nameTextField.text forKey:NAME_KEY];
[newDrink setValue:self.ingredientsTextView.text forKey:INGREDIENTS_KEY];
[newDrink setValue:self.directionsTextView.text forKey:DIRECTIONS_KEY];

// Add it to the master drink array and release our reference
[jobArray_ addObject:newDrink];

// Sort the array since we just added a new drink
NSSortDescriptor *nameSorter = [[NSSortDescriptor alloc] initWithKey:NAME_KEY ascending:YES selector:@selector(caseInsensitiveCompare:)];
[jobArray_ sortUsingDescriptors:[NSArray arrayWithObject:nameSorter]];

// Pop the modal view and go back to the list
[self dismissViewControllerAnimated:YES completion:NULL];
}
我是不是犯了一个错误,不把钱存起来?它加载我在plist中预设的数据,但不加载新条目


提前感谢

请将数据保存在pList中,如下所示:

    NSMutableDictionary *dict;

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentPath = [paths objectAtIndex:0];

    NSString *plistPath = [documentPath stringByAppendingPathComponent:@"myplist.plist"];

    NSLog(@"File path = %@", plistPath);

    NSFileManager *fileManager  =   [NSFileManager defaultManager];

    BOOL success = [fileManager fileExistsAtPath:plistPath];

    // This line saves the dictionary to pList
    [dict writeToFile:plistPath atomically:YES];

如何将其添加到当前代码中以保存字典中已经存在的三个值只需将最后一行添加到其中…在我的代码中按给定的名称获取plist的路径,并按照我的代码中提到的方式写入最后一行我是否应像这样添加该行[newDrink writefile:@“JobDirections.plist”原子性:是];我可以把这个项目发给你吗?我已经给你发了电子邮件:)