我在执行时收到“registerclass 的不明确使用
”错误
tableView.RegisterClass( cellClass: CustomTableViewCell.self,
forCellReuseIdentifier: "CustomCell"
)
CustomTableViewCell
是一个 Objective-c 类,它已包含在桥接 header 中。
我不明白这是怎么回事?谁能告诉我这个错误是什么意思?
最佳答案
您对 registerClass
的调用具有第一个参数的参数名称 (cellClass)。在 Swift 中,第一个参数名称被省略。
tableView.registerClass(CustomTableViewCell.self,
forCellReuseIdentifier: "CustomCell")
错误显示 registerClass 使用不明确的原因是编译器无法判断您要调用哪一个。 UITableView 上有两个 registerClass
方法:
func registerClass(cellClass: AnyClass, forCellReuseIdentifier identifier: String)
func registerClass(aClass: AnyClass, forHeaderFooterViewReuseIdentifier identifier: String)
您的调用与其中任何一个都不匹配,因此它不明确。
关于ios - Swift 中 registerclass 的使用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39412343/