我從plist文件中讀取問題 我的Settings.plist文件保存在我的項目中(嘗試進出資源文件夾) 沒有任何方法谷歌和stackOverFlow必須提供工作。我不知道我錯過了什麼。 代碼:從plist中讀取
NSString *pListPath = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
NSMutableDictionary *settings = [[[NSMutableDictionary alloc] initWithContentsOfFile:pListPath] retain];
BOOL touch = [[settings objectForKey:@"Touch"] boolValue];
NSLog(@"%@",touch ? @"TOUCH IS YES" : @"TOUCH IS NO");
我試圖獲得* plistPath許多不同的方法,一個NSBundle,只是一個文件名字符串。還試過NSMutabelDictionary,regulat NSDictionary,NSArray,NSMutableArray
沒有什麼似乎工作。 嘗試plist中第一行設置爲根字典,仍然沒有運氣..
任何幫助將apreciated .. Settings.plist有一個單一的價值Touch和它的關鍵是YES 非常感謝!
編輯: 這裏的plist中:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Root</key>
<dict>
<key>Touch</key>
<true/>
</dict>
</dict>
</plist>
什麼是'settings'後'initWithContentsOfFile值:'回報?另外,編輯你的問題並粘貼在'Settings.plist'文件的內容中。 – 2012-02-02 03:36:34
如何判斷它自己的設置的值? – 2012-02-02 03:43:46
使用'NSLog'或調試器。 – 2012-02-02 03:49:50