Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash #1

Open
shmidt opened this issue Jul 17, 2014 · 7 comments
Open

crash #1

shmidt opened this issue Jul 17, 2014 · 7 comments

Comments

@shmidt
Copy link

shmidt commented Jul 17, 2014

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.

@tomknig
Copy link
Owner

tomknig commented Jul 18, 2014

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?

@shmidt
Copy link
Author

shmidt commented Jul 18, 2014

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
Copy link
Author

shmidt commented Jul 18, 2014

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];

@tomknig
Copy link
Owner

tomknig commented Jul 18, 2014

Awesome!
I have implemented that suggestion in 6000dc1 👍

@tomknig
Copy link
Owner

tomknig commented Jul 18, 2014

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.

@shmidt
Copy link
Author

shmidt commented Jul 18, 2014

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

@shmidt
Copy link
Author

shmidt commented Jul 18, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants