ios - Swift 中 registerclass 的使用不明确

标签 ios swift

我在执行时收到“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/

相关文章:

ios - 将视频保存到文档而不是相册

ios - 异构集合文字只能推断为 '[String : Any]' ;如果这是有意的,请添加显式类型注释

swift - 创建一个没有后退按钮的 NavigationLink SwiftUI

ios - 如何以编程方式更改 UICollectionView 单元格位置

ios - Magical Record 快速删除所有记录

ios - 如何找到此系统警报的 UI View ?

ios - 在多个 WKWebView 之间共享 session

ios - 在 Swift 中的 UITextView 上放置阴影

ios - UITableView 上的 Swift 信号 SIGABRT 错误

ios - Xamarin iOS 应用程序无法提交到 TestFlight 错误 ITMS-90700