【发布时间】:2020-11-02 05:09:23
【问题描述】:
这是我创建的模型:
struct Friends: Codable{
var name:String
var position:String
var details:[Detail]
}
struct Detail: Codable{
var detail:String
}
我想在表格视图中详细说明。我该怎么做?
var data = [Friends]()
TableView 是:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let data = data[indexPath.row]
let dataDetail = data.dataDetail[indexPath.row]
cell.textLabel?.text = "\(dataDetail)"
return cell
}
【问题讨论】:
-
您的 Friends 结构中没有 dataDetail 属性,如果您想要的内容是 details 属性的内容,请在 textLabel 中解释您期望的输出
-
问题的标题令人困惑,而描述不充分。请更新两者。您想在用户点击
Friendcell 时打开Detail单元格吗?
标签: arrays json swift uitableview struct