splinesoft / SSDataSources

Flexible data sources for your UITableView and UICollectionView.
Other
199 stars 23 forks source link

Public NSFetchedResultsController property. #6

Closed BasitAli closed 11 years ago

BasitAli commented 11 years ago

Move

@property (nonatomic, strong) NSFetchedResultsController *controller;

as a public property so that subclasses os SSCoreDataSource can access the controller.

jhersh commented 11 years ago

Sure, can do.

I'm curious, can you tell me more about your SSCoreDataSource subclass?

BasitAli commented 11 years ago

My Collection and Table views were programmed to show an extra "Add New" cell at the end. This is what my subclass looks like,

- (id)itemAtIndexPath:(NSIndexPath *)indexPath {
    if( indexPath.row < self.itemCount )
        return [self.controller objectAtIndexPath:indexPath];

    return nil;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    id <NSFetchedResultsSectionInfo> sectionInfo = [self.controller sections][(NSUInteger)section];
    return (NSInteger)[sectionInfo numberOfObjects] + 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    id <NSFetchedResultsSectionInfo> sectionInfo = [self.controller sections][(NSUInteger)section];
    return (NSInteger)[sectionInfo numberOfObjects] + 1;
}
jhersh commented 11 years ago

Added in d1932eb.