0
我试图将数据保存到每个人的应用程序中的plist,但它将其保存到每个人,所以例如,如果我有一个眼睛的颜色领域,我在textfield for John Doe,它为其他人保存了Brown,有没有办法在应用程序中保存这些信息,而不是使用plist?我有没有运气尝试:将数据保存到每个对象或个人的plist
-(NSString *)pathofFile{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsfolder = [paths objectAtIndex:0];
return [docsfolder stringByAppendingFormat:@"data.plist"];
}
这里是我在我的观点做负载代码:
- (void)viewDidLoad {
[self loadPerson];
[super viewDidLoad];
NSString *filepath = [self pathofFile];
if ([[NSFileManager defaultManager]fileExistsAtPath:filepath]) {
NSArray *array = [[NSArray alloc]initWithContentsOfFile:filepath];
Drinfo.text = [array objectAtIndex:0];
[array release];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationWillTerminate:) name: UIApplicationWillTerminateNotification object:app];
这里是我为我的saveperson方法的一部分:
NSMutableArray *array = [[NSMutableArray alloc]init];
[array addObject:self.Drinfo.text];
[array writeToFile:[self pathofFile] atomically:YES];
[array release];
一些代码将是很有益的。这听起来像是代码中存在一个相当基本的错误,它会构建数据结构以进入plist,如果我们能够看到它,我们可以很容易地修复它。 – David 2010-08-08 01:54:54
thx大卫,我发布的代码 – adea 2010-08-08 20:15:29