3lvis / DATASource

Core Data's NSFetchedResultsController wrapper for UITableView and UICollectionView
Other
106 stars 27 forks source link

DATASource does not call tableview delegate methods while using with Objective-C umbrela #32

Closed cyupa closed 8 years ago

cyupa commented 8 years ago

I'm trying DATASource in a project and it doesn't seem to work.

I setup the DATASource object accordingly:

    NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Session"];
    request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];
    NSManagedObjectContext *context = [[CodecampDataStack sharedStack].dataStack mainContext];

    DATASource *dataSource = [[DATASource alloc] initWithTableView:self.tableView
                                                    cellIdentifier:kSessionTableViewCellReusableIdentifier
                                                      fetchRequest:request
                                                       mainContext:context
                                                       sectionName:nil
                                                     configuration:^(UITableViewCell * _Nonnull cell, NSManagedObject * _Nonnull item, NSIndexPath * _Nonnull indexPath) {

                                                         cell.textLabel.text = [item valueForKey:@"name"];
                                                     }];
    self.tableView.dataSource = dataSource;

But it seems that the tableView delegate methods (inside DATASource) are not called. calling po dataSource.objectsCount returns, as expected, 67.

Project can be found here: https://github.com/cyupa/Codecamp-iOS UITableViewClass: SessionsTableViewController.

cyupa commented 8 years ago

tableView.reloadData doesn't do the trick. public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell still isn't called even though numberOfSectionsInTableView returns 1 and numberOfRowsInSection returns 67.

3lvis commented 8 years ago

Hi @cyupa,

I looked at your project and the issues seem to be happening because Storyboards does things differently.

One of this is that - (void)setupDatasource is being called before the DATAStack setup has allocated all the things. Then self.tableView.dataSource = dataSource is being set after the tableView set up is finished.

I'll try adding a Storyboard example to reproduce your issues and find a way to fix them. Thanks for reporting this!

I haven't faced any of this issues myself because I don't use Storyboards on my projects. You can find an example of a Storyboard-less setup here:

https://github.com/hyperoslo/Sync/tree/master/Examples/DesignerNews

cyupa commented 8 years ago

I'll try some stuff myself in the following days.

3lvis commented 8 years ago

Hi @cyupa,

I've been trying to get this working but the main issue seems to be related to Storyboards. I would recommend to use this without Storyboards as a workaround. I hope that helps.

Best,

3lvis commented 8 years ago

Demo on how to use this with Storyboards https://github.com/3lvis/StoryboardDATASourceAndDataStackDemo

cyupa commented 8 years ago

👍 Thanks @3lvis