Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSFetchedResultsController with multiple section logic

I have a list of items that are added to a shopping list. Each item has a department, and a flag to say whether it has been collected or not.

I would love to use a single table view to display this. The problem is, I need to group the sections by department, and then add a final additional section at the bottom for collected items (regardless of departments).

I can create a fetchedResultsController filtering out collected = yes and sorting by department easily enough. But I need this additional section appended with those items where collected = yes.

Should I be trying to create a fetchedResultsController with a sophisticated query to do this? Or try to manually add a section and some rows? If so, from where? A second FRC? Is it possible to have two FRCs feed into a single tableview?

like image 742
Ben Packard Avatar asked Jul 15 '26 14:07

Ben Packard


1 Answers

Ben,

The NSFetchedResultsController is designed to provide a single fetch to fill a table view. But you have the choice of how that data is fed into the table view. You can manually translate the fetched items where ever you want. You can add sections, extra rows, whatever. That is why they surface the update of the model in the delegate. They give you the chance to make those adjustments.

Hence, if you construct your model such that a single fetch does the job, then you have a great deal of flexibility on how you use it.

Andrew

like image 134
adonoho Avatar answered Jul 20 '26 15:07

adonoho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!