Cell from Xib with Swift 3

后端 未结 2 1831
执念已碎
执念已碎 2021-02-04 09:47

I already read and saw some videos about this subject but i can\'t get this to work. Im trying to a cell from a xib instead of the storyboard.

This is my ViewController

相关标签:
2条回答
  • 2021-02-04 10:33

    You need to register your nib object.

    In viewDidLoad():

    let nib = UINib(nibName: "nameOfYourNibFile", bundle: nil)
    
    tableView.register(nib, forCellReuseIdentifier: "yourIdentifier")
    

    You also need to return the number of sections:

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    0 讨论(0)
  • 2021-02-04 10:33

    First of all, You have to register your nib object.

    yourTable?.register(UINib(nibName: "yourCustomCell", bundle: nil), forCellReuseIdentifier: "cellIdentifier")
    
    0 讨论(0)
提交回复
热议问题