我是否必须创建一些带有数据的虚拟硬编码数组以在表视图中查看首选项?

问题描述:

如何创建一个 UITableViewController 以分组样式(如 iPhone 设置)显示一些硬编码数据.例如,我需要在具有组样式的表格中显示一些菜单选项.现在,我知道使用表格并且已经完成了.但是我不确定我应该如何处理表视图为构建表而读取的数据.这些行只显示一些菜单选项,例如订单"、评论"、关于我们",然后恕我直言,我必须使用该数据创建一些数组并存储在 NSUserDefaults 中.我对吗?

How to create a UITableViewController that displays some hardcoded data in grouped styled (like iPhone settings). For example I need to show some menu options in a table with group style. Now, I know to work with tables and have done it already. But I'm not sure about how should I deal with data that table view will read for constructing the table. Those rows just present some menu options like "order", "review", "about us" then IMHO I have to create some array with that data and store in NSUserDefaults. Am I right?

创建数据的 plist 文件.它可以包括每个组的项目数组.在您的项目中包含 plist 并将其读入以供您的数据源使用.这可以很好地将数据与 UI 分离.

Create a plist file of your data. It can include arrays of items for each group. Included the plist in your project and read it in for use by your datasource. That creates a nice decoupling of data from UI.