Could not cast value of type 'UITableViewCell' to '(AppName).(CustomCellName)'

前端 未结 12 1664
一生所求
一生所求 2020-12-02 23:03

I\'m currently trying to create a custom table view cell using xCode 6.3 swift 1.2. For some reason in the cellforRowAtIndexPath method, I just can\'t seem to set up my cell

相关标签:
12条回答
  • 2020-12-02 23:06

    In my case i'm not changed the UITableViewCell class. Initially it's DetailsTableViewCell class but i removed and added new class called TableViewCellClass. But I forget to change the cell class name here.

    So once again check and change TableViewCell class name here see below screen shot

    0 讨论(0)
  • 2020-12-02 23:07

    Swift 3 syntax:

    self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    
    0 讨论(0)
  • 2020-12-02 23:08

    Firstly I suggest you to recreate your cell class, using CocoaClass. I had quite similar mistake - I created a CollectionViewCell, and when I recognised my mistake, I decided to simply rename the parent class. However, compiler haven't notice any mistake, I had this error during build.

    0 讨论(0)
  • 2020-12-02 23:09

    Keep the custom cell class name and cell id same:

       self.tableView.register(CustomCell.self, forCellReuseIdentifier: "CustomCell")
    
    0 讨论(0)
  • 2020-12-02 23:10

    Register your CustomCell in viewDidLoad() method:

    self.tableView.register(CustomCell.self, forCellReuseIdentifier: "Cell")
    
    0 讨论(0)
  • 2020-12-02 23:13

    In viewDidLoad()

    // register custom table view cell from nib
    self.tableView.registerNib(UINib(nibName: "MessageCell", bundle: nil), forCellReuseIdentifier: "messageCell")
    
    0 讨论(0)
提交回复
热议问题