Pac*_*ong 1 xcode uitableview tableview ios swift
我试图在Storyboard中创建一个自定义的TableView Cell.加载ViewController时显示正确的数据.但是,当我开始来回滚动时,数据显示在随机单元格中,而不是在正确的位置.我还试图以编程方式将Right Detail单元格的文本粗体化为:
if dayOfWeek!-1 == indexPath.row {
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: (cell.textLabel?.font.pointSize)!)
cell.detailTextLabel?.font = UIFont.boldSystemFont(ofSize: (cell.detailTextLabel?.font.pointSize)!)
}
Run Code Online (Sandbox Code Playgroud)
然而,类似的事情发生了:粗体看起来正确,文本在随机单元格中加粗.知道如何解决这个问题吗?谢谢!
小智 7
class CustomTableViewCell: UITableViewCell {
override func prepareForReuse() {
// your cleanup code
}
}
Run Code Online (Sandbox Code Playgroud)
在索引路径的单元格中
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: CustomTableViewCell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) as! CustomTableViewCell
if dayOfWeek!-1 == indexPath.row {
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: (cell.textLabel?.font.pointSize)!)
cell.detailTextLabel?.font = UIFont.boldSystemFont(ofSize: (cell.detailTextLabel?.font.pointSize)!)
}
return cell
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
385 次 |
| 最近记录: |