Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Segmented control to toggle through multiple tableviews

What I’m basically trying to is to implement the control segment/tableview as in Mailbox (see it around 2:00: http://www.youtube.com/watch?v=FG-h8pDXfoE&feature=youtu.be&t=2m)

I am using Core Data in one UITableViewController hooked up to a UITableView.

When user toggles the UISegmentedControl, the TableView is reloaded with a different set of NSPredicate, and UITableViewRowAnimationRight/Left, kind of makes it appear that that a different table view slides in and replaces the old one.

As the number of cells increase, the performance of this design decrease dramatically, and it could also look much better.

I can see a few different ways of going about it, but I figured I'd ask you guys for some pointers to head me in the right direction:

What is the best way to have a segmented control to toggle through multiple tableviews? Should these tableviews be connected to the same data source/delegate?

5 Answers

If you are dealing with a VERY large number of rows, and if you know the performance bottle neck is the movement of data, consider incorporating NSFetchResultsController. See this tutorial for more information:

http://www.raywenderlich.com/999/

And yes, you can also rewire the data source and delegate on toggle, too many ways to approach this it's hard to tell what's best without knowing the full design of your app.

The effect could be a navigation or pageview controller without a navigationBar embedded in a single view application with a separate toolbar drawn on top. So basically they are not refreshing the table view data, but literally advancing through the navigation/pageview stack and you are seeing different table views.

Would it be possible (and a good solution) to use one table view controller for three table views? Then as the user toggles the segmented controller in the navigation bar, current table view is replaced by the next one with a horizontally sliding motion?

In that case, should I have three different fetchedResultsControllers (one for each tableview), each with their own set of predicates and fetch requests - or should I only have one fetchedResultsController, and reset this, fetch new data with a new predicate, when the user toggles a new tableview.

Could performance be an issue?

The cells in the three tableviews are are the same entities in Core Data, the only difference is that they are either marked 'due' ,'deferred' and 'complete', which puts them in three different tables.

I am already using NSFetchResultsController. When the user toggles the UISegmentedControl, the NSFetchResultsController is set to nil, a new NSPredicate is used, and then the table is reloaded using this method:

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationRight];

The animation is not exactly what I'm looking for (I want this http://www.youtube.com/watch?v=FG-h8pDXfoE&feature=youtu.be&t=2m). The UITableViewRow-animations don't really illustrate the segment-to-segment feel.

However, the cells are fairly similar in all table toggles/filters - about the same as in Mailbox.

So what you're saying is add a Navigation Controller, remove it's navigationBar, add a toolbar on top, and have that toolbar advance through the stack?

I was not able to add that toolbar on top in the Storyboard

removed