3lvis / DATASource

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

Two DATASource instances with the same cellIdentifier but should be different #35

Closed tommypeps closed 8 years ago

tommypeps commented 8 years ago

My Model

capture d ecran 2015-11-04 a 15 06 45

MyViewController

@property (nonatomic) DATAStack *dataStack;
@property (nonatomic) DATASource *dataSource;
@property (nonatomic) DATASource *dataSourceCollection;
.
.
.
- (DATAStack *)dataStack
{
    if (_dataStack) return _dataStack;

    _dataStack = [[DATAStack alloc] initWithModelName:@"Model"];

    return _dataStack;
}
- (DATASource *)dataSource
{
    if (_dataSource) return _dataSource;
    _dataStack = [self dataStack];

    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Program"];
    request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"remoteID"
                                                              ascending:YES]];

    request.predicate = [NSPredicate predicateWithFormat:@"f2fEvent.remoteID == %@", self.event.remoteID];
    _dataSource = [[DATASource alloc] initWithTableView:self.tableView
                                           fetchRequest:request     
                                         cellIdentifier:@"SyncProgramCell"
                                            mainContext:self.dataStack.mainContext
                                          configuration:^(UITableViewCell *cell,
                                                          Program *item,
                                                          NSIndexPath *indexPath)
                   {

                      //Implementing Cell
                   }];

    return _dataSource;
}

-(DATASource*)dataSourceCollection
{
    if(_dataSourceCollection) return _dataSourceCollection;
    if (!_dataStack) {
        _dataStack = [self dataStack];
    }
    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Place"];
    request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"profile"
                                                              ascending:YES]];

    request.predicate = [NSPredicate predicateWithFormat:@"f2fEvent.remoteID == %@", self.event.remoteID];

    _dataSourceCollection = [[DATASource alloc] initWithCollectionView:self.collectionView
                                                          fetchRequest:request
                                                        cellIdentifier:@"SyncProfileCount"
                                                           mainContext:self.dataStack.mainContext
                                                         configuration:^(id cell, Place *item, NSIndexPath *indexPath)
    {

             // Implemantation Cell

    }];

    return _dataSource;

}

-(void)registerTableViewCell
{
    UINib *nib = [UINib nibWithNibName:@"ViewF2FDetail"
                                bundle:[NSBundle mainBundle]];
    UINib *nibCollection = [UINib nibWithNibName:@"SyncPlaceCell"
                                bundle:[NSBundle mainBundle]];

    //Add TableViewCell Config
    [self.tableView registerNib:nib
         forCellReuseIdentifier:@"SyncProgramCell"];

    //Add CollectionViewCell Config
    [self.collectionView registerNib:nibCollection
          forCellWithReuseIdentifier:@"SyncProfileCount"];
//    [self.collectionView registerClass:[JRProfileCollectionViewCell class]
//            forCellWithReuseIdentifier:@"SyncProfileCount"];

}

-(void)viewDidLoad
{
    [super viewDidLoad];
    [self registerTableViewCell];

    [self.tableView setDataSource:self.dataSource];
    [self.tableView setDelegate:self];

    [self.collectionView setDataSource:self.dataSourceCollection];
 .
 .
 .
}

I do understand as this ins possible

capture d ecran 2015-11-04 a 15 15 19

I see #25 but this error is not

3lvis commented 8 years ago

Yeah, this should be possible. A UIViewController with both UITableViewController and UICollectionViewController, right?

3lvis commented 8 years ago

There's a bug in your code.

-(DATASource*)dataSourceCollection
{
    if(_dataSourceCollection) return _dataSourceCollection;
    if (!_dataStack) {
        _dataStack = [self dataStack];
    }

//...
//...
//...
//...

    return _dataSource;
}

Should be

-(DATASource*)dataSourceCollection
{
    if(_dataSourceCollection) return _dataSourceCollection;
    if (!_dataStack) {
        _dataStack = [self dataStack];
    }

//...
//...
//...
//...

    return _dataSourceCollection;
}
tommypeps commented 8 years ago

@3lvis 😂 Thanks!!!