【发布时间】:2016-10-20 02:41:34
【问题描述】:
我有一个结构/模型,我存储一些 JSON 数据来填充我的 tableview:
import SwiftyJSON
struct MyData {
let valOne: Int
let valTwo: String
let valThree: Int
init(json: JSON) {
valOne = json["some_data"].intValue
valTwo = json["auc_data"].stringValue
valThree = json["auc_data"].intValue
}
}
然后在我的表格视图中,我有一个自定义单元格类,当我写出我的数据时会使用它:
let data = MyData[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell") as! CustomTableViewCell
cell.configureCellWithData(data)
我想要做的是将结构作为参数传递给 configureCellWithData() 但我不知道如何声明它。
而不是做类似的事情:
func configureCellWithData(dataOne: Int, dataTwo: String, dataThree: Int) {
}
然后
configureCellWithData(data.valOne,data.valTwo,data.valThree)
我不想有很多参数,而是想立即发送结构
【问题讨论】:
-
你试过这种方式吗? func configureCellWithData(data: MyData) { }
-
let data = MyData[indexPath.row]行没有意义。我假设您定义了一些属性,例如var dataObjects = [MyData]()或类似的东西,然后您将执行let data = dataObjects[indexPath.row]。
标签: ios swift xcode struct parameters