【发布时间】:2026-02-06 17:35:01
【问题描述】:
我正在尝试在自定义表格视图单元格中创建自定义复选框。
我有一个自定义表格视图单元格:
class CustomTableViewCell: UITableViewCell {
weak var delegate: CellDelegateT?
@IBOutlet var customCheckbox: VKCheckbox!
}
这是加载我的 tableView 的代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TransactionsTableViewCell
let customCheckbox = cell.customCheckbox!
customCheckbox.line = .thin
customCheckbox.bgColor = UIColor.white
customCheckbox.color = UIColor.black
customCheckbox.borderColor = UIColor.black
customCheckbox.borderWidth = 2
customCheckbox.cornerRadius = customCheckbox.frame.height / 2
}
我需要将构造复选框的代码放在哪里? cellForRowAt 位置不对吗?
当我在表格单元格之外使用代码时,它可以正常工作。这就是为什么我认为我将复选框创建代码放在错误的位置。
【问题讨论】:
标签: swift xcode uitableview