为什么我不能在 viewDidLoad 方法中的静态 UITableViewCell 中设置附件视图?

why I cannot set up an accessory view in my static UITableViewCell in viewDidLoad method?

我有一个包含 3 个静态 UITableViewCell 的表格视图。当用户进入该面板时,我想在第一个单元格上设置一个复选标记。在我的 viewDidLoad() 方法中,我调用:

tableView.cellForRow(at: IndexPath(row: 0, section: 0))?.accessoryType = .checkmark

但复选标记不存在。那我怎样才能从代码中分配它呢?

您应该将您的设置代码直接放在 UITableView 委托 (cellForRow) 中,不要在 viewDidLoad.

中调用