UITableView - registerClass with Swift

前端 未结 9 1974
一向
一向 2021-02-06 20:17

Is anyone else having an issue using the tableView.registerClass method with Swift?

It no longer comes in code completion for me (nor can I use it if manual

相关标签:
9条回答
  • 2021-02-06 20:53

    For swift 3 refer this. It works!

    Inside you viewdidload function

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

    0 讨论(0)
  • 2021-02-06 20:55

    Switching the order in which I called registerNib and registerClass worked for me!

    For some reason my app crashed when I had:

    ...registerNib.....

    ...registerClass...

    But ran fine when I had:

    ...registerClass...

    ...registerNib.....

    Hope that helps some of you.

    0 讨论(0)
  • 2021-02-06 20:59

    For swift 4

    self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
    
    0 讨论(0)
  • 2021-02-06 21:00

    Swift has once again renamed it to

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

    Really don't understand why they bothered so much about this particular naming

    0 讨论(0)
  • 2021-02-06 21:02

    It works for me perfectly.

    self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    

    Exactly as I have it above.

    0 讨论(0)
  • 2021-02-06 21:12

    I prefer to use TableViewCell.self to generate the identifier string. It can reduce the typing error.

    tableView.register(MyCell.self, forCellReuseIdentifier: String(describing: MyCell.self))
    
    0 讨论(0)
提交回复
热议问题