2012-09-12 26 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

所以我需要重新創建該文件? –