Tuomax
Tuomax

Reputation: 31

UiTableview not appearing on screen

For some reason my tableview doesn't show up at all even though every other element does. I tried the same code on a different project and it showed up perfectly.

Here are my tableview functions:

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    print("this will run")

    return 3
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! Cell

    cell.otsikko.text = "example"
    cell.kuvaus.text = "exampledesc"

    print("this code won't run")

    return cell
}

override func viewDidAppear(_ animated: Bool) {
    tableView.reloadData()
}

And here's some other cell setup:

class Cell : UITableViewCell {
    @IBOutlet weak var otsikko: UILabel!
    @IBOutlet weak var kuvaus: UITextView!
}

class HomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
    @IBOutlet weak var tableView: UITableView!

Image of the storyboard:

Storyboard

Image of the run application:

Run app

So, as you can see, it sort of skips the whole tableview and won't generate the cells. It could be about layouts and constraints, but honestly I have no idea.

Upvotes: 1

Views: 149

Answers (1)

swift2geek
swift2geek

Reputation: 1812

I think, first step would be to check your viewcontroller for outlets, and set datasource and delegate.

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

enter image description here

Upvotes: 1

Related Questions