TOMSSuggestionBar icon indicating copy to clipboard operation
TOMSSuggestionBar copied to clipboard

crash

Open shmidt opened this issue 11 years ago • 7 comments

Hi,

Thanks for the great control. I tried to run the example, and after I entered some text in the textfield, I've got a crash:

return [self.fetchedResultsController objectAtIndexPath:indexPath]; On line 206 in TOMSCoreDataFetchController.m

P.S. Crash happens when breakpoint on all exceptions is set.

shmidt avatar Jul 17 '14 15:07 shmidt

Hi Dmitry,

do you have any change to reproduce the crash and post more information about it? Do you maybe know what kind of exception was thrown?

tomknig avatar Jul 18 '14 10:07 tomknig

As I undestand, crash happens inside try-catch block:

- (NSManagedObject *)objectForIndexPath:(NSIndexPath *)indexPath
{
    NSInteger numberOfSuggestionFields = [self numberOfSuggestionFields];
    if (numberOfSuggestionFields % 2 == 0) {
        return [self.coreDataFetchController objectAtIndexPath:indexPath];
    } else {
        NSManagedObject *object;

        @try {
            NSInteger row = (indexPath.row - floorf(numberOfSuggestionFields / 2.f)) * 2;
            if (row < 0) {
                row = -row - 1;
            }
            NSIndexPath *recalculatedIndexPath = [NSIndexPath indexPathForRow:row inSection:indexPath.section];
            object = [self.coreDataFetchController objectAtIndexPath:recalculatedIndexPath];
        }
        @catch (NSException *exception) {
            object = nil;
        }

        return object;
    }
}

recalculatedIndexPath contains value outside of the range of coreDataFetchController objects. I'll think how to fix it.

shmidt avatar Jul 18 '14 11:07 shmidt

I also have a few comments: If you have an identical cells, there is no need to register every cell, just one. It will be re-used with different data.

[NSPredicate predicateWithFormat:@"%K LIKE[cd] %@", attributeName, [NSString stringWithFormat:@"*%@*", context]]; can be written as: [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", attributeName, context];

shmidt avatar Jul 18 '14 12:07 shmidt

Awesome! I have implemented that suggestion in 6000dc139ca93ce1150c7d29977aceb54de44ee6 :+1:

tomknig avatar Jul 18 '14 12:07 tomknig

It is necessary for the cells to have unique identifier to be able to sort them within the suggestion bar. It is true that they are identical but once instantiated they do have to stay in the same spot. Ignoring the position within the suggestion bar would cause the cells label to morph from unpredictable text and thus break the context sensitive appearance of the morph.

tomknig avatar Jul 18 '14 12:07 tomknig

@TomKnig Oh, I see... thanks for clarification.

shmidt avatar Jul 18 '14 12:07 shmidt

Instead of adding gesture recogniser to every cell, use delegate method - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ [self didSelectSuggestionAtIndexPath:indexPath]; }

shmidt avatar Jul 18 '14 18:07 shmidt