我正在创建一个简单的测验应用程序。我已经有一个 pList 文件,其中存储了我的所有问题,并为每个问题放入了“类别”键。 我的pList结构是这样的:
<plist version="1.0">
<dict>
<key>Questions</key>
<array>
<dict>
<key>Answers</key>
<array>
<string>(Answer Choice 1)</string>
<string>(Answer Choice 2)</string>
<string>(Answer Choice 3)</string>
<string>(Answer Choice 4)</string>
</array>
<key>Category</key>
<string>(Category Here)</string>
<key>CorrectAnswer</key>
<string>(Correct Answer Here)</string>
<key>Question</key>
<string>(Question Here)</string>
</dict>
</array>
我可以在测验模式下成功显示 pList 文件的内容。
但是,我想让用户可以选择或选择他们想要测试的类别。考虑到这一点,我计划创建一个由复选框组成的“设置” View ,用户可以在其中选择一个或多个他们喜欢的类别。
我的问题是,我应该使用什么代码才能仅显示具有用户选择的“类别”的“问题数组”? 如何将该代码连接到设置 View 的复选框?
这个想法是这样的:
用户将看到一个设置 View ,他们可以在其中选择一个或多个类别:
The "Settings" view with category checkboxes
然后,当测验模式开始时,他们将仅看到他们选择的“类别”中找到的问题:
最佳答案
要显示
您的类别作为复选框,请从 plist 字典中提取所有键。
NSArray *categories = [plistDictionary allKeys];
要选择类别下的特定问题,请将所选的复选框类别作为键传递,以从 plist 字典中检索特定数组。
NSarray *questions = [plistDictionary valueForKey:@"YourSelectedCategory"];
关于ios - 显示 pList 中特定的 "categories",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35053803/