【发布时间】:2015-03-08 15:54:00
【问题描述】:
我正在尝试将 Dictionary 键值放入我的 TableView。数据源是一个plist。
plist 是这样设置的:很遗憾,我还不能发布图片。
Root = Array
Item 0 = Dictionary
modelName = "SomeName"
modelType = "SomeType"
Item 1 = Dictionary (similar key : values)
Item 2 = Dictionary
Item 3 = Dictionary
所以它基本上是一个字典数组。我想遍历数组并在我的 TableView 标签中使用“modelName”值。
当我使用 println 时,我可以打印单个 Array 对象
if let path = NSBundle.mainBundle().pathForResource("models", ofType: "plist") {
if let array = NSArray(contentsOfFile: path) {
self.tableData = array
println(self.tableData[0])
}
}
但我想转换我的数据并调用一个特定的键值以在我的 tableView 中使用。我正在尝试为我的 plist 中的每个项目创建一个字典
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as DataSheetTableViewCell
var dict = NSDictionary(objectsAndKeys: self.tableData[indexPath.row])
cell.titleLabel.text = dict["modelName"] as? String
return cell
}
我对如何创建我的 plist 字典有点困惑。谢谢。
【问题讨论】: