无法在Swift中的UITableView上调用"registerClass"

And*_*age 5 objective-c uitableview ios swift

对Swift来说,这对Objective-C来说非常适合我.不确定这是否是语法问题或者我的项目设置不正确.

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

Cannot invoke 'registerClass' with an argument list of type '(UITableViewCell.Type, forCellReuseIdentifier: String)'

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?) {
    }
}
Run Code Online (Sandbox Code Playgroud)

谷歌一直没有很大的帮助,会感激一些帮助!

iCy*_*aul 0

您似乎尚未在故事板中为此表设置自定义类 - 类名称。您需要从下拉列表中选择 JobsViewController。然后你会得到

@IBOutlet weak var tableView: UITableView!
Run Code Online (Sandbox Code Playgroud)

在你的代码中。