UITableView - registerClass with Swift

前端 未结 9 2143
一向
一向 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 21:18

    For Swift 2.2 Register For Default Cell From Class

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



    For Swift 3.0 Register For Default Cell From Class

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



    For Swift 2.2 Register For Default Cell From Nib

    self.tableView.registerNib(UINib(nibName: "CustomCellName", bundle: nil), forCellReuseIdentifier: "CustomCellIdentifer")
    



    For Swift 3.0 Register For Default Cell From Nib

    self.tableView.registerNib(UINib(nibName: "CustomCellName", bundle: nil), forCellReuseIdentifier: "CustomCellName")
    

    Note: Storyboard created cell is called prototype cell and have some procedure to register prototype cell like Nib.And Don't forget to set the cell identifier like below.

提交回复
热议问题