Search code examples
iosxcodecore-dataquickdialog

QuickDialog and NSFetchedResultsController for a UITableView


I'm sure this is a stupid question, but unfortunately I'm a noob like a lot of people (well, maybe less so now adays haha...).

Anyways...

I have an existing project containing a UITableView that is populated via my own class (MyListTableViewController). This class currently subclasses an object that essentially sets up the NSFetchedResultsController.

Considering this fact, the examples and documentation I've read always show the need to subclass the QuickDialogController in order to access the QuickDialog features as it basically subclasses the UIViewController at the heart of it all..

The problem is I can't figure out how to allow using both the QuickDialogController AND the NSFetchedResultsController classes together for the same UITableView/Instance...

NSFetchedResultsController is being subclassed because it acts as the delegate to the UITableView and also because it monitors all UITableView events, etc. etc... things I'm sure most are well aware of... The problem is that I can see that the QuickDialogController also wants to act as basically the delegate to UIView (which our UITableView already subclasses)

So, this has my mind feeling like it's going to explode as I'm trying to make sense how to make these 2 objects play nicely together within the same collection...

Since my app is tightly coupled to core data, I need this functionality, but I want the power and beauty of QuickDialog..

So - is there a way I can subclass the QuickDialogController and then have the NSFetchedResultsController be used as a kind of delegate to it, or vice versa?

Again, sorry if this is a stupid/noob question... still learning but wanting to do this right...

Example (Current) Subclass layout I'm using for a UITableViewController...

MyListTableViewController.h

#import <UIKit/UIKit.h>
#import "CoreDataTableViewController.h"

@interface MyListTableViewController : CoreDataTableViewController

CoreDataTableViewController.h

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>

@interface CoreDataTableViewController : UITableViewController <NSFetchedResultsControllerDelegate>

@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic) BOOL suspendAutomaticTrackingOfChangesInManagedObjectContext;

-(void)performFetch;
@end

Maybe an alternative question here would be: Is it possible to utilize the QuickDialog operations without having to subclass the QuickDialogController. If so - what are the implications of doing this, and (most importantly) is there a small example? Would I just create an allocated instance of one of the 2?

I apologize in advance for any ignorance my question may expose....


Solution

  • What you're trying to do is not possible. ObjC doesn't allow for multiple inheritance, which is what you are trying to do. Even if it did, you would still have the problem of now having the core data dataSource/delegate and the QuickDialog datasource/delegate working at the same time.

    You need to decide one way or another: 1 - either inherit from the QuickDialog controller and then add logic to fetch data from CoreData and load into the Root elements yourself (and don't use the CoreDataTableViewController) or.. 2 - inherit from CoreDataTableViewController, and manually create the QuickDialogTableView and it's datasource/delegate on your class.

    Regarding #2, QD was not created for this kind of usage, IMHO. You would be much better going with option 1 and move the loading of CoreData data to an external class, which you can then load into your Root elements. If you have hundreds/thousands of rows, though, I wouldn't use QD for this.