我正在寻找在Swift中使用可重用单元格的正确方法。
如何只调用setup
方法一次?
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "AwesomeCell")
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "AwesomeCell") as UITableViewCell? ?? UITableViewCell()
self.setup(cell: cell) // I want this to be called only once
cell.textLabel?.text = self.data[indexPath.row]
return cell
}
func setup(cell: UITableViewCell) {
cell.accessoryType = .disclosureIndicator
}
谢谢。