使用Swift时registerclass的含义不明确。

4
当我执行某个操作时,出现了一个错误,错误信息是“ambiguous use of registerclass”。
tableView.RegisterClass( cellClass: CustomTableViewCell.self,
                         forCellReuseIdentifier: "CustomCell"
                         )

CustomTableViewCell 是一个 Objective-c 类,在桥接头文件中已经被包含。

我无法弄清楚哪里出了问题,有人可以告诉我这个错误是什么意思吗?

1个回答

7

您调用registerClass方法时,第一个参数名为cellClass。在Swift中,第一个参数名是省略的。

tableView.registerClass(CustomTableViewCell.self, 
                        forCellReuseIdentifier: "CustomCell")

错误提示"ambiguous use of registerClass"是因为编译器无法确定你要调用哪一个。在UITableView中有两个registerClass方法:
func registerClass(cellClass: AnyClass, forCellReuseIdentifier identifier: String)
func registerClass(aClass: AnyClass, forHeaderFooterViewReuseIdentifier identifier: String)

你的调用不符合这两者之一,因此它是有歧义的。


今晚我会试着把它删除。但是第一个参数名称与“ambiguous use”错误有什么关系呢? - AlexW
我明白了。通过删除参数名称,使其与第一个调用匹配。太棒了:)非常感谢伙计。应该请你喝一杯啤酒。 - AlexW

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接