4

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?

David Eisenstat
  • 64,237
  • 7
  • 60
  • 120
user2336702
  • 343
  • 4
  • 12

3 Answers3

3

Take a look at this pod: https://github.com/xmartlabs/XLMailBoxContainer. It makes the UI animation among the view controllers. These view controller can extend UITableViewController or any other view controller.

UITableViewCell swipe animation can be accomplished using https://github.com/alikaragoz/MCSwipeTableViewCell.

I hope this could help you!

mtnBarreto
  • 282
  • 1
  • 3
  • 9
2

It really depends how different each of these table views is. If they are quite similar, it's probably easiest to just share the delegate and data source and have some conditional code.

In fact you can just have a single table view, but have different cells / configuration depending on your current context. Could be as simple as having adding some conditions to

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

Another approach would be to use view controller containment. You would create a UITableViewController for each and then have parent view controller with segmented control which swaps child view controller accordingly.

As for the animation and performance, I can't really see any problem. You can get the animations without much effort if you use NSFetchedResultsController, see an example here: https://developer.apple.com/library/ios/documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html.

kkodev
  • 2,557
  • 23
  • 23
  • These tableviews are going to show the same items, only in different "states" - basically like a simple to-do list where the segmented control would toggle between to-do items that were either incomplete or complete. Right now I do have it set up with one delegate and data source, but the animation does get slightly choppy when there's a lot of items in the various lists. – user2336702 Dec 13 '13 at 21:07
  • I would go with the first approach then. Just configure your cell depending on the current context. – kkodev Dec 13 '13 at 21:08
  • This is what I actually have set up right now. The only thing is that the performance drops, and that the animation doesn't really illustrate the segment-to-segment feel (as in Mailbox). I use swipe gestures on the cells, so this is kind of important. I'm left with View Controller Containment then? – user2336702 Dec 13 '13 at 21:14
  • I imagine it will be a bit tricky to have the same table view but have the animation as well. You could always take a snapshot of your current table view, display it on top of your previous table, offset the table by the screen width and animate the transition. As for the performance, are you sure you are reusing the cells correctly? Also is your table view frame not bigger that window bounds? – kkodev Dec 13 '13 at 21:22
  • I am using a standard TableViewController from the storyboard, so I'm assuming that frame should be good. Maybe I am not doing doing the animation right. The segmented control triggers the following code: `_fetchedResultsController = nil; [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationRight];` – user2336702 Dec 13 '13 at 21:37
  • However, I think a better solution would have different table views, so that I can achieve a similar feel: http://www.youtube.com/watch?v=FG-h8pDXfoE&feature=youtu.be&t=2m – user2336702 Dec 13 '13 at 21:44
  • Yes, if you want more control and more ways to customise then go with the view controller containment approach. – kkodev Dec 14 '13 at 00:10
0

See SBSegmentedViewController. I wrote it for exactly what you're trying to do.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
  • How would I do the animation? (http://www.youtube.com/watch?v=FG-h8pDXfoE&feature=youtu.be&t=2m) – user2336702 Dec 14 '13 at 08:35
  • Also, should I use one data source/delegate for all the tables? I am using Core Data and NSFetchedResultsController. – user2336702 Dec 14 '13 at 08:46
  • It currently doesn't do the animation, but that's not hard to add. You would have two completely separate table view controllers that could stand on their own if they needed to be. So separate delegate, and separate instance of `NSFetchedResultsController`. – Scott Berrevoets Dec 14 '13 at 15:38