TOMSSuggestionBar
TOMSSuggestionBar copied to clipboard
crash
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.
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?
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.
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];
Awesome! I have implemented that suggestion in 6000dc139ca93ce1150c7d29977aceb54de44ee6 :+1:
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 Oh, I see... thanks for clarification.
Instead of adding gesture recogniser to every cell, use delegate method - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ [self didSelectSuggestionAtIndexPath:indexPath]; }