Michael Osofsky
Michael Osofsky

Reputation: 13115

Static contents of UITableViewController disappeared

I've made this mistake several times so I thought I'd share the solution. It often happens while I'm converting a mocked up iOS app to a real app. While I'm mocking up I use the storyboard in Xcode without assigning sublcasses to the UIViewControllers. But then when I'm happy with the design I go in to write the code and after I create the subclasses and assign them to the storyboard screens.

A common problem I encounter is my UITableViewController screens have their static content disappear when I assign the subclass.

Steps to reproduce problem:

  1. Drag a TableViewController out onto storyboard
  2. Set the content to Static Cells
  3. Fill in some static cells as part of prototyping
  4. When you're happy with the prototype subclass UITableViewController
  5. Go to the Utilities=>Identity Inspector and set the Custom Class to your subclass

At this point when I run the project in the simulator the screen's static content has disappeared.

Upvotes: 0

Views: 128

Answers (1)

Michael Osofsky
Michael Osofsky

Reputation: 13115

This is the missing step from the sequence above.

  1. Delete the code generated by Xcode when it created your subclass

Code to remove:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 0;
}

You'll need to keep this code out until you need to change the content from Static Cells to Dynamic Cells.

Upvotes: 1

Related Questions