Cell from Xib with Swift 3

后端 未结 2 1830
执念已碎
执念已碎 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
    }
    

提交回复
热议问题