ksa_coder ksa_coder - 11 months ago 74
iOS Question

Static table not showing

I created a table view controller and from drop down in Xcode selected content to be static cells. I placed buttons in those cells but when I run I get an empty table. I didn't enter any code in the TableViewController class as I thought this was not needed.

How can this be fixed?

This is the way it looks in Xcode and then when it runs in simulator:

enter image description here

enter image description here

Answer Source

You may miss some stuff:

1) Check whether your tableView has set the class named as that on in your code. You find the input field to type the name of the class in Attributes inspector of the tableView.

2) Check whether you implemented methods, that comform to UITableViewDelegate and UITableViewDataSource Protocol.

func numberOfSections(in tableView: UITableView) -> Int {
    // I see you only have 1 section now
    return 1

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//you should return appropriate number
   return 3

3) Check whether your table is properly connected from Storyboard to your UIViewController =>

if your tableView is inside UIViewController, check whether you set delegate and datasource for tableView in your controller (CTRL drag from table to FileOwner - rounded yellow icon in storyboard scene frame.)