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