UITableView not display on iPhone simulator

I created a simple tableview using the code below with a UITableView in the storyboard and when i lauch the iphone simulator nothing appears.

I an hoping someone help me trouble shoot this issue. thank you in advance!!!

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    @IBOutlet weak var tableView: UITableView!
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")!
        let text = data[indexPath.row]
        cell.textLabel?.text = text
        return cell
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        for i in 0...1000{
        data.append("\(i)")
        }
        // Do any additional setup after loading the view.
    }
    private var data: [String] = []

}

Replies

Several things to check:


You did not set the delegate for the tableView nor the dataSource in code.

- Did you do it in IB ?

- if you want to do in code:

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.datasource = self


Problem may not come from tableView.

- Do you get any view on screen (other than tableView) ?

- Have you a scene delegate ? If so, did you update the info.plist ?

Look at this : https://forums.developer.apple.com/message/386601#386601