我正在尝试为 iPhone 制作一个测验应用程序。我不太清楚如何开始。会有数百个问题,所以我不想为每个问题构建一个单独的视图。我应该以什么格式将问题导入应用程序以阅读,然后将其设置为按随机顺序和类别(即一次所有问题,仅数学问题,仅英语问题等)做问题?
3 回答
会有数百个问题,所以我不想为每个问题构建一个单独的视图。
当然不是。将问题视为应用程序运行的数据。您可能希望每种问题格式都有一个视图,例如多项选择、简答等。
我应该以什么格式将问题导入应用程序进行阅读
That's totally up to you -- it's a design decision, so choose whatever works best for you. When faced with an arbitrary-seeming decision like this, it's often a good idea to stay flexible. For example, you might decide to put the questions in a text file for now, but design your code so that it's easy to plug code that reads a different format.
and then set it up to do questions in random order, and by category (i.e. all questions at once, only math questions, only english questions, etc.)?
Sounds like you might want to consider storing the questions in some sort of database. You can then query the database with different criteria to get different sets of questions.
您可以使用 CoreData 存储问题,然后在应用程序首次加载时从 JSON 文件或类似文件中读取它们。这也将允许您在将来通过 REST api 更新问题。
你可以看看RestKit它将为你处理很多解析。
在将所有问题加载到数据库中之后,剩下的就取决于您了,但是在 CoreDate 上构建视图非常容易。
我建议您在数据库中组织您的问题,例如:
Questions Table
QuestionID | Question | Answer | Category
1 | What is 2 + 2 | 5 | math
2 | What is the capital of Argentina? | Buenos Aires | geography
这样,使用单个视图并使用 SQL 访问问题会很简单。