{"action":"created","issue":{"url":"https://api.github.com/repos/jessesquires/JSQMessagesViewController/issues/406","labels_url":"https://api.github.com/repos/jessesquires/JSQMessagesViewController/issues/406/labels{/name}","comments_url":"https://api.github.com/repos/jessesquires/JSQMessagesViewController/issues/406/comments","events_url":"https://api.github.com/repos/jessesquires/JSQMessagesViewController/issues/406/events","html_url":"https://github.com/jessesquires/JSQMessagesViewController/issues/406","id":38215337,"number":406,"title":"JSQMessagesViewController + NSFetchedResultsController - Always fetching all the results.","user":{"login":"rburton","id":31757,"avatar_url":"https://avatars.githubusercontent.com/u/31757?v=3","gravatar_id":"","url":"https://api.github.com/users/rburton","html_url":"https://github.com/rburton","followers_url":"https://api.github.com/users/rburton/followers","following_url":"https://api.github.com/users/rburton/following{/other_user}","gists_url":"https://api.github.com/users/rburton/gists{/gist_id}","starred_url":"https://api.github.com/users/rburton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rburton/subscriptions","organizations_url":"https://api.github.com/users/rburton/orgs","repos_url":"https://api.github.com/users/rburton/repos","events_url":"https://api.github.com/users/rburton/events{/privacy}","received_events_url":"https://api.github.com/users/rburton/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jessesquires/JSQMessagesViewController/labels/questions%20&%20help","name":"questions & help","color":"bfdadc"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-07-18T21:53:49Z","updated_at":"2015-12-20T17:23:37Z","closed_at":"2014-07-23T15:55:59Z","body":"I'm trying to render a conversation using NSFetchedResultsController to prevent loading the entire thread. I suspect it's an issue since I'm ordering the conversation by date sent and that's triggering the loading of the entire thread starting from the first conversation?\r\n\r\n\r\n```objective-c\r\n+ (NSFetchedResultsController *)findByConversation:(Conversation *)conversation withContext:(NSManagedObjectContext *)context {\r\n    NSEntityDescription *entityDescription = [self newEntityDescription:context];\r\n    NSFetchRequest *searchReuest = [[NSFetchRequest alloc] init];\r\n    searchReuest.predicate = [NSPredicate predicateWithFormat:@\"conversation = %@\", conversation];\r\n    searchReuest.entity = entityDescription;\r\n    NSSortDescriptor *orderBy = [[NSSortDescriptor alloc] initWithKey:@\"sentAt\" ascending:YES];\r\n    [searchReuest setSortDescriptors:@[orderBy]];\r\n    [searchReuest setFetchBatchSize:20];\r\n\r\n    NSError *error;\r\n    NSFetchedResultsController *controller = [[NSFetchedResultsController alloc]\r\n            initWithFetchRequest:searchReuest\r\n            managedObjectContext:context\r\n              sectionNameKeyPath:nil\r\n                       cacheName:nil];\r\n    BOOL success = [controller performFetch:&error];\r\n    if(!success){\r\n        // Failure..\r\n    }\r\n    return controller;\r\n}\r\n```\r\n\r\nThe code in my controller is \r\n\r\n```objective-c\r\n-(void) load {\r\n    fetchedResultsController = [Message findByConversation:self.conversation withContext:self.conversation.managedObjectContext];\r\n    fetchedResultsController.delegate = self;\r\n    NSError *error;\r\n    [fetchedResultsController performFetch:&error];\r\n}\r\n- (id <JSQMessageData>)collectionView:(JSQMessagesCollectionView *)collectionView messageDataForItemAtIndexPath:(NSIndexPath *)indexPath {\r\n    Message *message = [fetchedResultsController objectAtIndexPath:indexPath];\r\n    return [message toJSQMessage];\r\n}\r\n\r\n- (UIImageView *)collectionView:(JSQMessagesCollectionView *)collectionView bubbleImageViewForItemAtIndexPath:(NSIndexPath *)indexPath {\r\n    Message *msg = [fetchedResultsController objectAtIndexPath:indexPath];\r\n    JSQMessage *message = [msg toJSQMessage];\r\n    if (![message.sender isEqualToString:_conversation.userId]) {\r\n        return [JSQMessagesBubbleImageFactory outgoingMessageBubbleImageViewWithColor:[UIColor jsq_messageBubbleGreenColor]];\r\n    }\r\n    return [JSQMessagesBubbleImageFactory incomingMessageBubbleImageViewWithColor:[UIColor jsq_messageBubbleLightGrayColor]];\r\n}\r\n\r\n- (UIImageView *)collectionView:(JSQMessagesCollectionView *)collectionView avatarImageViewForItemAtIndexPath:(NSIndexPath *)indexPath {\r\n    JSQMessage *message = [self.messages objectAtIndex:(NSUInteger) indexPath.item];\r\n    if ([message.sender isEqualToString:_conversation.userId]) {\r\n        UIImageView *friendAvatarImage = [[UIImageView alloc] initWithImage:friendAvatar];\r\n        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buzzFriend)];\r\n        singleTap.numberOfTapsRequired = 2;\r\n        friendAvatarImage.userInteractionEnabled = YES;\r\n        [friendAvatarImage addGestureRecognizer:singleTap];\r\n        return friendAvatarImage;\r\n    }\r\n    return [[UIImageView alloc] initWithImage:yourAvatar];\r\n}\r\n\r\n- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {\r\n    id sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];\r\n    return [sectionInfo numberOfObjects];\r\n}\r\n\r\n- (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {\r\n    JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *) [super collectionView:collectionView cellForItemAtIndexPath:indexPath];\r\n    JSQMessage *msg = [self.messages objectAtIndex:(NSUInteger) indexPath.item];\r\n\r\n    if ([msg.sender isEqualToString:self.sender]) {\r\n        cell.textView.textColor = [UIColor blackColor];\r\n    } else {\r\n        cell.textView.textColor = [UIColor whiteColor];\r\n    }\r\n    cell.textView.linkTextAttributes = @{NSForegroundColorAttributeName : cell.textView.textColor, NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle | NSUnderlinePatternSolid)};\r\n    cell.delegate = self;\r\n    return cell;\r\n}\r\n"},"comment":{"url":"https://api.github.com/repos/jessesquires/JSQMessagesViewController/issues/comments/166136509","html_url":"https://github.com/jessesquires/JSQMessagesViewController/issues/406#issuecomment-166136509","issue_url":"https://api.github.com/repos/jessesquires/JSQMessagesViewController/issues/406","id":166136509,"user":{"login":"GuyKahlon","id":3619880,"avatar_url":"https://avatars.githubusercontent.com/u/3619880?v=3","gravatar_id":"","url":"https://api.github.com/users/GuyKahlon","html_url":"https://github.com/GuyKahlon","followers_url":"https://api.github.com/users/GuyKahlon/followers","following_url":"https://api.github.com/users/GuyKahlon/following{/other_user}","gists_url":"https://api.github.com/users/GuyKahlon/gists{/gist_id}","starred_url":"https://api.github.com/users/GuyKahlon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GuyKahlon/subscriptions","organizations_url":"https://api.github.com/users/GuyKahlon/orgs","repos_url":"https://api.github.com/users/GuyKahlon/repos","events_url":"https://api.github.com/users/GuyKahlon/events{/privacy}","received_events_url":"https://api.github.com/users/GuyKahlon/received_events","type":"User","site_admin":false},"created_at":"2015-12-20T17:23:37Z","updated_at":"2015-12-20T17:23:37Z","body":"Hi @rburton, have you found solutions to this problem? do you have reference / example hoe to work with JSQMessagesViewController + NSFetchedResultsController and paging ?\r\nThanks."}}