我正在将UIViews加载到我的tableview单元格内容视图中,但当我滚动浏览tableview时,只有一个单元格加载其视图。它为每个单元格加载正确的视图,但它只加载一个,然后随着新单元格从底部出现而消失。所有数据都通过函数makeTableViewRowView
(填充uview的字符串数组)在本地加载。当我滚动时,TableView只加载一个单元格的内容
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: expenseCell, for: indexPath)
tableViewRow = makeTableViewRowView(indexPath: indexPath)
tableViewRow.translatesAutoresizingMaskIntoConstraints = false
cell.contentView.addSubview(tableViewRow)
cell.selectionStyle = .none
let margins = cell.contentView.layoutMarginsGuide
tableViewRow.centerYAnchor.constraint(equalTo: margins.centerYAnchor).isActive = true
tableViewRow.leadingAnchor.constraint(equalTo: margins.leadingAnchor).isActive = true
tableViewRow.trailingAnchor.constraint(equalTo: margins.trailingAnchor).isActive = true
tableViewRow.heightAnchor.constraint(equalToConstant: 40).isActive = true
return cell
}
什么是'tableViewRow'? –
@ Mr.Bista它只是一个拥有UIView原因的属性makeTableViewRowView返回一个UIView –
它的因为'tableViewRow'只初始化一次,这就是为什么它出现在最后一个单元格只有 –