iOS Quick Tip – UITableView with static cells not showing up

If you’ve ever tried to create a UITableView with static cells, you may have run across some difficulties in getting your cells to actually show up.

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.

16 Comments

  1. I removed,i got [ViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance.
    How can i?

    Reply

  2. Ok but if i remove those methods and i want the cells to have switchable images. Swappable images, sorry, so that when the user taps them, they switch, thus I implement didSelectRowAtIndexPath. How would I handle that situation?

    Reply

Leave a Reply to clqiao Cancel reply

Your email address will not be published. Required fields are marked *