使用 SQLite 数据库进行问答游戏
对于测验游戏,我想将问题存储在包含主键、问题、4 个答案和正确答案 7 列的数据库中,然后运行一个随机方法,该方法会选择问题并使用以下内容填充多个文本字段数据。
然后,我会将“正确答案”列的值存储在变量中,以便稍后在用户选择答案时调用 if 语句。
我尝试了很多涉及 SQLite 数据库的教程,但我非常不清楚如何执行以下操作:
将我的 xcode 项目连接到数据库(存储在资源文件夹中的只读数据库)
将数据库加载到对象中(或者在每个问题的运行时加载每一行以节省内存?)
- 创建一个随机选择行的方法,然后用数据填充文本字段并将正确答案列存储到变量中。
我已经用头撞桌子好几个星期了,所以任何帮助将不胜感激!
谢谢你们!
For a Quiz game I would like to store the questions in a database containing 7 columns for the Primary key, Question, 4 answers, and the correct answer then run a random method that would pick on of the questions and populate several text fields with the data.
I would then store the value for the "correct answer" column in a variable for a if statement called later on when the user selects an answer.
I have attempted so many tutorials involving SQLite databases that I am very unclear how to do the following:
Connect my xcode project to the database (a read-only database stored in the resources folder)
Load the database into an object (or load each row at run time at each question to save memory?)
Make a method that randomly selects a row, then populates text fields with the data and stores the correct answer column into a variable.
I have been banging my head on my desk for several weeks now, so ANY help would be GREATLY appreciated!
Thanks guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iPhone 编程教程 – 使用 SQLite 创建待办事项列表第 1 部分
iPhone SDK 教程:从 SQLite 数据库读取数据
在 SQLite 中选择随机行
这里是 核心数据 和 如果您想尝试一下如何选择随机行
iPhone Programming Tutorial – Creating a ToDo List Using SQLite Part 1
iPhone SDK Tutorial: Reading data from a SQLite Database
Selecting a Random Row in SQLite
And here is Core Data and How to select a random row if you want to give that a try