Reza Shayestehpour
Reza Shayestehpour

Reputation: 1703

Content of static cells not appearing UITableView

I have a UITableViewController that has a table view with static cells. I have added some costume cells with UIImageView and UILabel in them. Everything looks fine in the xcode storyboard: enter image description here

since the cells are static I do NOT implement the datasource methods here's my code for the table view controler:

    #import "MainTableViewController.h"

    @interface MainTableViewController ()

    @end

    @implementation MainTableViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
    }

    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    @end

but when I run the code in the simulator the cells' content won't appeare: enter image description here

here's the Scene hierarchy:

enter image description here

Upvotes: 6

Views: 6641

Answers (8)

Matthew Dong
Matthew Dong

Reputation: 1

I have come across the same problem these days. As mentioned by Aryan, I have to add constraints to Labels in the master view of UISplitViewController. Otherwise the content is not "disappear" but at the so left of the tableview cell that it is off the screen bounds. Set the trailing margin to superview works for me.

Upvotes: 0

TheRealRonDez
TheRealRonDez

Reputation: 2807

UITableView with static cells not showing up for me either - I tried to remove and re-add the segue. Everything was properly set up. The trick....

The trick is to remove the following row, cell, and section methods from your UITableViewController subclass. They are automatically added by Xcode, but if you are using static cells, you don’t want them in your class.

– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Once you have removed these methods, your cells will show up correctly.

Upvotes: 19

Jitendra Kulkarni
Jitendra Kulkarni

Reputation: 833

I had the same problem. If you have a custom TableViewController but the TableViewCell Style is not set to custom this happens. I got around by changing the UITableViewController from my custom controller to the generic one. My guess is that if the controller is custom, then we are saying that we will supply the data programmatically so the storyboard data is not presented. There must be away to get around it, but I am too new to iOS to investigate. Besides, for prototyping generic UITableViewController works well enough. So: Go to the "Main Table View Controller" Select the identity inspector. Change the class from your custom class to UITableViewController

Or use your custom controller but change TableViewCell.Style to Custom in the Attributes Inspector

Upvotes: 2

Bernhard Grabowski
Bernhard Grabowski

Reputation: 469

Did you set the dataSource and the delegate for the UITableViewController to self ?

Upvotes: 0

Aryan
Aryan

Reputation: 2735

I think you have problem with constraints! If you have wrong constraint for elements inside cell, elements will not shown!

Upvotes: 5

Aneeq Anwar
Aneeq Anwar

Reputation: 1332

Please make sure you have selected "Static Cells" in content option of Table View

TableView

Upvotes: 6

Wizkid
Wizkid

Reputation: 1035

I have a UITableViewController that has a table view with static cells

Are you sure that your static table cells are within a UITableViewController and not within a UITableView embedded within a UIViewController? Storyboard will let you add table cells to a table view embedded within a standard view controller, but this wont work at runtime. Depending upon the version of ios you may or may not get an error. If the answer is yes, then you need to add the static table cells directly to the UI**Table**View**Controler**.

Upvotes: 2

jakenberg
jakenberg

Reputation: 2113

Creating prototypes in Storyboard is all fine and dandy, but you still need to inform the tableView property of the cells at runtime.

To do this, you need to name each cell with a reuseIdentifier:

enter image description here

Then you name each reuse identifier explicitly in your code:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

Your problem resides in the fact that you didn't implement the dataSource, which does exactly as it's titled: supplies the data.

Good luck

Upvotes: -3

Related Questions