我有一个结构如:
struct Test {
var name: String?
var value: Float?
var isfavorite:String?
init(name: String, value: Float, favorite: String){
self.name = name
self.value = rawRate
self.favorite = favorite
}
}
我根据Test Struct
存储了一个字符串var TestInformation = [String:Test]()
当我想根据TestInformation的内容填充tableview时,我收到以下错误:
[String : Test]' does not have a member named 'name'
以下是我用来填充tableview的行:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
cell.testlabel?.text = TestInformation[indexPath.row].name
}
我不明白我做错了什么,也许有人指出我正确的方向。
谢谢:)
编辑:
我通过执行以下操作向testInformation添加信息:
let testInformation = [
Test(name: "Foo1", value: 1.32, isfavorite: "favorite"),
Test(name: "Foo2", value: 1.27, isfavorite: "favorite")]