ios - 无法在 Swift 中对 UITableView 调用 "registerClass"

标签 ios objective-c uitableview swift

Swift 的新手,这对我来说很适合 Objective-C。不确定这是语法问题还是我的项目设置不正确。

首先,这是我看到的错误(在 JobsViewController 的第 5 行,以 self.tableView.registerClass 开头的行):

无法使用类型为“(UITableViewCell.Type, forCellReuseIdentifier: String)”的参数列表调用“registerClass”

JobsViewController

class JobsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 0
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        return UITableViewCell()
    }

    func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    }
}

Google 的帮助不是很大,希望能提供一些帮助!

最佳答案

Swift 3 中运行良好

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")

关于ios - 无法在 Swift 中对 UITableView 调用 "registerClass",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30332859/

相关文章:

ios - 对枚举的引用是不明确的 objective-c

ios - 处理需要处理多个选择器的手势?

Java 等效于 Objective-C 实例类型?

Objective-C:如何在运行时更改对象的类?

iOS 分发证书过期 - Ad Hoc 应用程序

ios - NSString 对象的 length 属性有一个不正确的值

ios - 单击按钮展开表格 View 单元格

ios - UITableView 在 ScrollView 时停止更新内容?

ios - 无法将 UITableViewDataSource 与自定义单元格一起使用

ios - 互联网可用后,将终止的 iOS 应用程序置于前台状态