Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot invoke "registerClass" on UITableView in Swift

New to Swift, this worked fine for me with Objective-C. Not sure if this is a syntax issue or if I have my project set up incorrectly.

First of all, this is the error that I'm seeing (on line 5 of JobsViewController, the line that starts with 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?) {
    }
}

Google hasn't been very helpful, would appreciate some help!

like image 213
Andrew Page Avatar asked May 19 '15 17:05

Andrew Page


2 Answers

Works fine in Swift 3

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
like image 87
Lito Avatar answered Oct 04 '22 18:10

Lito


 var cell : UITableViewCell = UITableViewCell()

 feedTableView.registerClass(cell.classForCoder, forCellReuseIdentifier: "cellidentifier")

Try with above lines of code

like image 29
Sakshi Avatar answered Oct 04 '22 17:10

Sakshi