【发布时间】:2011-10-02 18:32:37
【问题描述】:
我已按照这个答案将数据写入 plist
How to write data to the plist?
但到目前为止,我的 plist 根本没有改变。
这是我的代码:-
- (IBAction)save:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"drinks" ofType:@"plist"];
NSString *drinkName = self.name.text;
NSString *drinkIngredients = self.ingredients.text;
NSString *drinkDirection = self.directions.text;
NSArray *values = [[NSArray alloc] initWithObjects:drinkDirection, drinkIngredients, drinkName, nil];
NSArray *keys = [[NSArray alloc] initWithObjects:DIRECTIONS_KEY, INGREDIENTS_KEY, NAME_KEY, nil];
NSDictionary *dict = [[NSDictionary alloc] initWithObjects:values forKeys:keys];
[self.drinkArray addObject:dict];
NSLog(@"%@", self.drinkArray);
[self.drinkArray writeToFile:path atomically:YES];
}
我需要做一些额外的事情吗?
我是 iPhone SDK 的新手,因此我们将不胜感激。
【问题讨论】: