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.
Thank you Marty. I commented first two methods and missed the 3rd one. Cool tip
Thanks, glad to know it helped someone!
[…] As we have seen previously, getting a UITableView with static cells to show up can be a bit tricky. You need to remove some of the table methods. However, if you want to dynamically show and hide sections at runtime, you will need add one of them back in and put in a little bit of extra effort. […]
ha, thanks!
Thank You, saved me a lot of frustration!
Thanks! 🙂
thanks a lot for your post. very good advice.
very good advice, thanks a lot.
I removed,i got [ViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance.
How can i?
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?
In this case, I think you’ll have to manually grab the cells and update them in didSelectRowAtIndexPath, instead of trying to do it in cellForRowAtIndexPath.
This StackOverflow post talks about how to grab the cells: http://stackoverflow.com/a/9994023/184630
Wish I’d found this an hour ago! Thanks for the tip.
Thanks so much. You made my day.
Thanks … you saved a lot of struggle.
Bro….Awesome..Thank you very much
Bro….Thank you man…
Thank you im just staring my first app and didn’t have no idea of wants is going on, you save me 😀
Thanks ,save me lot of time.