Swift对registerclass的模糊使用 [英] ambiguous use of registerclass with Swift
问题描述
做
tableView.RegisterClass( cellClass: CustomTableViewCell.self,
forCellReuseIdentifier: "CustomCell"
)
CustomTableViewCell
是Objective-c类,已包含在桥接头文件中.
CustomTableViewCell
is an Objective-c class and it's been included in a bridging header.
我不知道这是怎么回事?谁能告诉我这个错误是什么意思?
I couldn't figure out what's wrong with it? Can anyone tell me what does that error mean?
推荐答案
您对registerClass
的调用具有第一个参数的参数名称(cellClass).在Swift中,第一个参数名称被省略.
Your call to registerClass
has a parameter name (cellClass) for the first parameter. In Swift, the first parameter name is omitted.
tableView.registerClass(CustomTableViewCell.self,
forCellReuseIdentifier: "CustomCell")
该错误表明使用registerClass的原因是因为编译器无法告诉您您要调用的是哪一个. UITableView上有两种registerClass
方法:
The reason the error says ambiguous use of registerClass is because the compiler can't tell which one you are trying to call. There are two registerClass
methods on UITableView:
func registerClass(cellClass: AnyClass, forCellReuseIdentifier identifier: String)
func registerClass(aClass: AnyClass, forHeaderFooterViewReuseIdentifier identifier: String)
您的通话与以上任何一项都不匹配,因此模棱两可.
Your call doesn't match either of these, therefore it's ambiguous.
这篇关于Swift对registerclass的模糊使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!