我试过这段代码将我的数据复制到plist,但它在追加.can的情况下不工作。任何一个都可以告诉我一个附加数据的好方法吗?
NSMutableDictionary * nameDictionary = [NSMutableDictionary dictionary];任何人可以帮助我将数据附加到plist文件?
NSString *plistPath=[[NSBundle mainBundle] pathForResource:@"listNew" ofType:@"plist"];
[nameDictionary setValue:nameEntered.text forKey:@"name"];
[nameDictionary setValue:company.text forKey:@"company"];
[nameDictionary setValue:designation.text forKey:@"designation"];
// create dictionary with values in UITextFields
NSMutableArray *plist = [NSMutableArray arrayWithContentsOfFile:plistPath];
if (plist == nil) plist = [NSMutableArray array];
[plist addObject:nameDictionary];
[plist writeToFile:plistPath atomically:YES];
UIAlertView *tellErr = [[UIAlertView alloc] initWithTitle:title message:@"succsefully created" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[tellErr show];
[email protected]"";
[email protected]"";
[email protected]"";
当你说它不工作时,你是否看到崩溃或数组没有字典,你预计将被添加到最后?从我看到的,你上面的代码看起来很好。 – Sam 2012-03-12 14:06:16
当我试图插入它第一次它从plist中删除整个数据,或者如果我正在查看列表,然后去插入它崩溃 – ashwin19 2012-03-12 14:15:52
如果您的问题得到解答,请将其标记为绿色支票 – 2012-03-13 12:55:31