【发布时间】:2021-11-05 07:12:03
【问题描述】:
我使用表格视图创建了一个记分板,我想突出显示表格的第一行。当我运行应用程序时,第一行按预期突出显示,但是当我滚动表格时,突出显示了几个单元格而不是第一个单元格。
这是我的代码;
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "score", for: indexPath) as! ScoreTableViewCell
if indexPath.row == 0 {
cell.backgroundImageView.image = UIImage(named: "firstClass")
}
cell.nicknameLabel.text = self.sortedResults[indexPath.row]["nickname"] as? String
cell.scoreLabel.text = " \(indexPath.row + 1)"
return cell
}
【问题讨论】:
-
使用 2 个不同的单元原型。一个用于第 0 行,带有 backgrounImagzView,另一个不带。
标签: ios arrays swift xcode uitableview