pronebird / UIScrollView-InfiniteScroll

UIScrollView ∞ scroll category
MIT License
1.06k stars 148 forks source link

addInfiniteScrollWithHandler never returns! xcode 7 ios 8.4 simulator #22

Closed kalitas closed 8 years ago

kalitas commented 8 years ago

[self.productsCollectionView addInfiniteScrollWithHandler:^(UICollectionView* collectionView) {

        PFQuery *queryProducts = [PFQuery queryWithClassName:@"products"];
        [queryProducts whereKey:@"objectId" containedIn:[aProvider objectForKey:@"products"]];
        [queryProducts whereKey:@"market" equalTo:self.market];
        [queryProducts setLimit:100];
        [queryProducts setSkip:_skip];
        [queryProducts findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
         {                 
             dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                 dispatch_async(dispatch_get_main_queue(), ^{
                     [MBProgressHUD hideHUDForView:self.view animated:YES];
                     [self.productsCollectionView setAlpha:1.0];
                     [self.searchBar setHidden:NO];
                 });
             });

             if (!error)
             {
                 _skip += 100;

                 NSMutableArray *indexPaths = [NSMutableArray new];
                 NSInteger index = weakSelf.productsOfProviderArray.count;

                 // create index paths for affected items
                 for(PFObject *product in objects) {
                     NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index++ inSection:0];

                     [weakSelf.productsOfProviderArray addObject:product];
                     [indexPaths addObject:indexPath];
                 }

                 // Update collection view
                 [collectionView performBatchUpdates:^{
                     // add new items into collection
                     [collectionView insertItemsAtIndexPaths:indexPaths];
                 } completion:^(BOOL finished) {
                     // finish infinite scroll animations
                     [collectionView finishInfiniteScroll];
                 }];
                 //self.productsOfProviderArray = [self sortProductsArrayAlphabetically:objects];
                 //[self.productsCollectionView reloadData];
             }
         }];
    }];

here is the collection object (just to show its not null): po self.productsCollectionView <UICollectionView: 0x7b27ea00; frame = (0 257; 320 311); clipsToBounds = YES; alpha = 0; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x795ebc60>; layer = <CALayer: 0x795eb010>; contentOffset: {0, 0}; contentSize: {320, 10}> collection view layout: <UICollectionViewFlowLayout: 0x795ebe30>

pronebird commented 8 years ago

Hi,

What do you mean never returns?

kalitas commented 8 years ago

Hi pronbird, it means that the code after this line: [self.productsCollectionView addInfiniteScrollWithHandler:^(UICollectionView* collectionView) { is not being read by the program... i mean this this code is not being used: PFQuery queryProducts = [PFQuery queryWithClassName:@"products"]; [queryProducts whereKey:@"objectId" containedIn:[aProvider objectForKey:@"products"]]; [queryProducts whereKey:@"market" equalTo:self.market]; [queryProducts setLimit:100]; [queryProducts setSkip:_skip]; [queryProducts findObjectsInBackgroundWithBlock:^(NSArray objects, NSError *error) {
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ dispatch_async(dispatch_get_main_queue(), ^{ [MBProgressHUD hideHUDForView:self.view animated:YES]; [self.productsCollectionView setAlpha:1.0]; [self.searchBar setHidden:NO]; }); });

         if (!error)
         {
             _skip += 100;

             NSMutableArray *indexPaths = [NSMutableArray new];
             NSInteger index = weakSelf.productsOfProviderArray.count;

             // create index paths for affected items
             for(PFObject *product in objects) {
                 NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index++ inSection:0];

                 [weakSelf.productsOfProviderArray addObject:product];
                 [indexPaths addObject:indexPath];
             }

             // Update collection view
             [collectionView performBatchUpdates:^{
                 // add new items into collection
                 [collectionView insertItemsAtIndexPaths:indexPaths];
             } completion:^(BOOL finished) {
                 // finish infinite scroll animations
                 [collectionView finishInfiniteScroll];
             }];
             //self.productsOfProviderArray = [self sortProductsArrayAlphabetically:objects];
             //[self.productsCollectionView reloadData];
         }
     }];
pronebird commented 8 years ago

The block you provide is executed when user scrolls to the bottom of the view. It won't be automatically called on first run.