Search code examples
iosxcodeuitableviewuinavigationcontrolleruitabbarcontroller

Cells disappear when connecting to custom class


I have a static cell UITableViewController in a UINavigationController in a UITabBarController.

When I create a custom class for UITableViewController and set it, all cells in UITableView disappear after build. I can see them in designer but not in Simulator nor device.

I'm new to iOS developing so forgive if I'm making an obvious mistake.


Solution

  • To everyone who have the same struggle. It doesn't matter if you have the UITableViewController in a UINavigationController or not, after creating custom class you should comment or delete the following methods if you have static cells:

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
    
        // Configure the cell...
    
        return cell
    }