2012-09-12 23 views
0

我在我的应用程序中有一个属性列表,我已经改变了所有不同字段的值,但是当应用程序关闭时,所有设置都被删除。下面是我使用的代码:属性列表不保存iOS

NSBundle *mainBundle = [NSBundle mainBundle]; 
    NSString *path = [mainBundle pathForResource:@"Settings" ofType:@"plist"]; 
    //NSNumber *str = [dict objectForKey:@"Auto_Save"]; 
    NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; 
     [data setObject:[NSNumber numberWithBool:sender.on] forKey:@"Auto_Save"]; 
     [data writeToFile:path atomically:YES]; 

回答

0

你不能写回存储在应用程序包中的文件。你需要把它写入'磁盘'。

+0

我该怎么做? –

+0

只需获取文档文件夹(或库文件夹,或其他)的路径并在其中写入文件即可。 http://stackoverflow.com/questions/5619719/write-a-file-on-ios – TomSwift

+0

所以我需要重新创建该文件? –