Skip to main content

Posts

Showing posts from May, 2019

Expanding/Collapsing TableView Sections - iOS

I could not figure out a way to get this functionality as class extension, which would have been nice. But this is not possible if you need an instance variable to keep track of something. The finished subclass will look and behave just like the original Twitter app for iPhone does. We start out by creating a new UITableView subclass which has a NSMutableSet instance variable to contain the section numbers which are already expanded. Don’t let yourself be daunted by the sheer amount of code. That’s really much ado about nothing. UITableViewControllerWithExpandoSections.h @interface UITableViewControllerWithExpandoSections : UITableViewController { NSMutableIndexSet * expandedSections; } NSIndexSet and the mutable cousin NSMutableIndexSet allow you to store an index, i.e. a number. It has methods to add such a number, remove it and query if it is contained in it. Being a set means that it is not ordered and each entry is automatically unique. Here’s the c...