unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard

前端 未结 22 2166
面向向阳花
面向向阳花 2020-12-12 17:33

I am fairly new to coding in general and really new to Xcode (Swift). I understand that I need to register a nib or a class but I don\'t understand \'where or how?\'.

<
22条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-12 18:23

    It used to work on swift 3 and swift 4 but now its not working.

    like

    self.tableView.register(MyTestTableViewCell.self, forCellReuseIdentifier: "cell")
    

    So I have tried the most of the solutions mentioned above in swift 5 but did not get any luck.

    Finally I tried this solution and it worked for me.

    override func viewDidLoad() 
    {
    
        tableView.register(UINib.init(nibName: "MyTestTableViewCell", bundle: nil), forCellReuseIdentifier: "myTestTableViewCell")
    }
    

提交回复
热议问题