0
我正在向alist写plist数据返回我的nill值..我必须将数据追加到前面的数组值。但是价值观alwys空.. 下面是代码:写入/追加数据到Plist返回nill
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"a.plist"];
// set the variables to the values in the text fields
// create dictionary with values in UITextFields
NSDictionary *plistDict = [NSDictionary dictionaryWithObject:@"c" forKey:@"Id"];
if ([[NSFileManager defaultManager] fileExistsAtPath:plistPath])
{
array = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
[array addObject:plistDict];
[array writeToFile:plistPath atomically:YES];
NSLog(@"array%@",array);
}
else
{
NSArray *array = [NSArray arrayWithObject:plistPath];
[array writeToFile:plistPath atomically:YES];
}
即使是第一次,你的数组总是零吗?或者,它在“if”块或“else”块中返回nil的位置? – 2015-04-06 04:44:21
alwys在IF条件下返回 – user3226440 2015-04-06 17:23:50