我有一個屬性列表文件,用於存儲問題和答案數據。在這個文件中,我有一個數組的集合,在這些數據中我存儲了不同的類別和問題。但是我似乎無法訪問這些數據?訪問Plist數組/目標 - 目標C
屬性文件;
<?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>Category1</key>
<array>
<array>
<string>Question1</string>
<string>Answer1</string>
</array>
<array>
<string>Question2</string>
<string>Answer2</string>
</array>
<array>
<string>Question3</string>
<string>Answer3</string>
</array>
<array>
<string>Question4</string>
<string>Answer4</string>
</array>
</array>
</dict>
</plist>
下面我使用通過使用兩個簡單的按鈕逐步訪問屬性列表文件;
-(IBAction)nextleft {
[self bingsound];
if (questionCounter > 1) {
questionCounter -= 1;
}
[self nextQuestion];
}
-(IBAction)nextright {
[self bingsound];
if (questionCounter < 20) {
questionCounter += 1;
}
[self nextQuestion];
}
-(void)nextQuestion {
NSArray *pair;
pair = [categories objectAtIndex:questionCounter];
plistQuestion = [pair objectAtIndex:0];
plistAnswer = [pair objectAtIndex:1];
abbreviation.text = plistQuestion;
}
我正在填充類別數組,如下所示;
categories = [NSArray arrayWithContentsOfFile:@"questions.plist"];
你能在文本編輯器中打開你的屬性列表,並張貼開場白嗎?該截圖看起來不正確,第一項應稱爲「根」,通常不能通過plist編輯器進行編輯。你有一個無效的屬性列表或字典作爲根對象 - 在調試器中,檢查你的類別數組是否被初始化爲。 – jrturton
剛纔補充說,現在讓你看看。 – Kolors