我試過這段代碼將我的數據複製到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