试图将自定义单元格添加到我的项目中,下面的代码将在寄存器行返回错误UINib Argument labels '(nibName:, Bundle:)' do not match any available overloads。
Xcode 9 beta 6
@IBOutlet var MTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
MTableView.delegate = self as? UITableViewDelegate
messageTableView.dataSource = self
MTableView.register(UINib(nibName: "MCell", Bundle: nil), forCellReuseIdentifier: "CustomCell")
}发布于 2017-09-12 12:02:00
你把大写和小写混为一谈。在Swift中,所有函数参数都以小写字母开头。变化
UINib(nibName: "MCell", Bundle: nil)至
UINib(nibName: "MCell", bundle: nil)发布于 2017-09-12 12:11:36
简单地说,您可以使用泛型来避免此类错误。
extension UITableView {
func registerNib<T: UITableViewCell> (_ type: T.Type) {
let nib = UINib(nibName: T.className, bundle: nil)
self.register(nib, forCellReuseIdentifier: T.className)
}
}现在您可以简单地按以下方式注册单元格:
self.tableView.registerNib(MyInfoViewCell.self)我使用这个扩展https://github.com/sanjaymhj/SwiftyStarters/blob/master/Extensions/UIView%2BExtension.swift来避免这种错误。您可以看到在readme https://github.com/sanjaymhj/SwiftyStarters/blob/master/README.md#extensions中注册单元格和去队列的用途。
https://stackoverflow.com/questions/46175833
复制相似问题