我有一個數組的plist包含2串看到圖像:arrayWithContentsOfFile無法讀取plist文件
http://imageshack.us/photo/my-images/263/myplist.png/
,並在我的viewDidLoad
我補充一點:
NSString *file = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
NSArray *array = [NSArray arrayWithContentsOfFile:file];
NSLog(@"array = %@", array);
但我爲什麼總是得到null
?感謝幫助。
UPDATE:解決的辦法是,你需要手動編輯plist文件(Xcode4使用Dictionnary默認)
<?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">
<array>
<array>
<string>HO</string>
<string>HI</string>
</array>
</array>
</plist>
發佈你的完整代碼.. – Aravindhan 2011-06-02 04:49:00
@funnyCoder你檢查路徑是否存在?也許在那裏貼一個[[[NSFileManager defaultManager] fileExistsAtPath:file]'? – 2011-06-02 04:51:24
@Aravindhanarvi這是我的完整代碼:)。 – funnyCoder 2011-06-02 04:52:40