I have a UITableViewController displaying core data. My data entity has 5 properties. I want to view the data in sections in the group table view. Using a segmented control on the tableViewController, I want to view them by property A when the A segment is selected, property B when B is selected, and C when C is selected.
To clarify: let’s say that property A is ‘brand’. When the ‘brand’ segment is selected, I want to have the header for the group read ‘BrandX’ and then list grouped all the data that has a brand X, in the first grouped section. The next section will be labeled ‘BrandY’, and so on. Similarly for ‘size’ and ‘material’ segments, for example.
So, in summary, one table view controller that displays the table in sections three different ways, controlled by the segmented control.
I tried using a switch statement for the segmentedControl.selectedSegmentIndex and then using different NSSortDescriptors for each case. Didn’t work.
I tried using if statements in the fetchedResultsController in a similar fashion. Not happening.
I’m just not seeing this. Anyone with ideas?
Thanks
To make this work you will recreate your fetchedResultsController each time the SegmentControl is changed. Set an IBAction for the segment control that will:
In fetchedResultsController set your sortkey using the selectedSegmentIndex, and
then use that to set the sort descriptors and section namekeypath and be sure to set cache to nil.