timothyarmes / TAFetchedResultsController

A version of NSFetchedResultsController that provides for having empty sections
MIT License
43 stars 7 forks source link

fix for indexPathForObject:sectionObject #11

Open solodyashkin opened 5 years ago

solodyashkin commented 5 years ago
- (NSIndexPath *)indexPathForObject:(id)object
{
    if ([object isKindOfClass:NSManagedObject.class])
    {
        NSEntityDescription *entity = [(NSManagedObject*)object entity];
        if ([entity isEqual:self.itemFetchRequest.entity])
        {
            NSIndexPath *indexPath = [_nsFetchedResultsController indexPathForObject:object];
            return [self convertNSFetchedResultsSectionIndexToUITableViewControllerSectionIndex:indexPath];
        }
        else if ([entity isEqual:self.sectionFetchRequest.entity])
        {
            NSUInteger objIdx =
            [self.sections indexOfObjectPassingTest:^BOOL(TASectionInfo *si, NSUInteger idx, BOOL * _Nonnull stop) {
                return si.theManagedObject == object;
            }];
            if (objIdx != NSNotFound){
                 return [NSIndexPath indexPathWithIndex:objIdx];
            }
        }
    }
    return nil;
}