chathura
chathura

Reputation: 161

Static cell in UITableViewController not showing content in simulator

I'm using UITableViewController static cells and added UILabel and text box to it. I even added constraints. But when I run the program the cells are empty.

Here are my screenshots:

enter image description here

enter image description here

I Just found out

override func viewWillAppear(animated: Bool) {
        self.navigationController?.setToolbarHidden(false, animated: true)

    }

    override func viewWillDisappear(animated: Bool) {
        self.navigationController?.setToolbarHidden(true, animated: true)
    }

above code make it disapear

Upvotes: 3

Views: 5504

Answers (6)

Ramprasath Selvam
Ramprasath Selvam

Reputation: 4428

enter image description here And

override func numberOfSections(in tableView: UITableView) -> Int {
            // #warning Incomplete implementation, return the number of sections
            return 1
        }

        override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            // #warning Incomplete implementation, return the number of rows
            return 3
        }

Upvotes: 0

Naishta
Naishta

Reputation: 12343

In Swift 2, tested the below fix for the question

'Comment-out' the below auto-generated/boiler plate code that comes along when you subclass UITableViewController (as you are using static cells, they may not be used)

  override func numberOfSectionsInTableView(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
    }

Upvotes: 11

chathura
chathura

Reputation: 161

After i updated the following 2 functions return it worked again.

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 15
}

Upvotes: 2

Lars Christoffersen
Lars Christoffersen

Reputation: 1739

If you are using static cell with custom layout as you are here, the class for the tableview should not be your custom tableviewcontroller class. Try and set your tableview and cell as the dumps below. If you, on the other hand, wants to fill the cell content dynamically, you need to make a class for the custom cell and also handle the filling of the cell in cellForRowAtIndexPath and also use dynamic prototype cells. Apple has some good explanations here and here

UITableViewController

UITableViewCell

Upvotes: 1

ak2g
ak2g

Reputation: 1673

It seems that you haven't defined data source and delegate This might help you. https://guides.codepath.com/ios/Table-View-Guide

Upvotes: 0

pacification
pacification

Reputation: 6018

Maybe you forget to set Custom Class for your TableViewController?
Try this:

  1. Go to storyboard.
  2. Select your TableViewController.
  3. Go to Show the identity inspector (3rd icon in right panel).
  4. Set Class to your MyCustomTableViewController class (if this class doesn't exist, create it).
  5. Run your project.

Upvotes: 2

Related Questions