UICollectionView reloadData not functioning properly in iOS 7

后端 未结 17 1357
北荒
北荒 2020-11-27 11:18

I\'ve been updating my apps to run on iOS 7 which is going smoothly for the most part. I have noticed in more than one app that the reloadData method of a

相关标签:
17条回答
  • 2020-11-27 11:42

    You can use this method

    [collectionView reloadItemsAtIndexPaths:arayOfAllIndexPaths];
    

    You can add all indexPath objects of your UICollectionView into array arrayOfAllIndexPaths by iterating the loop for all sections and rows with use of below method

    [aray addObject:[NSIndexPath indexPathForItem:j inSection:i]];
    

    I hope you understood and it can resolve your problem. If you need any more explanation please reply.

    0 讨论(0)
  • 2020-11-27 11:46

    Reloading some items didn't work for me. In my case, and only because the collectionView I'm using has just one section, I simply reload that particular section. This time the contents are correctly reloaded. Weird that this is only happening on iOS 7 (7.0.3)

    [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
    
    0 讨论(0)
  • 2020-11-27 11:46

    Swift 5 – 4 – 3

    // GCD    
    DispatchQueue.main.async(execute: collectionView.reloadData)
    
    // Operation
    OperationQueue.main.addOperation(collectionView.reloadData)
    

    Swift 2

    // Operation
    NSOperationQueue.mainQueue().addOperationWithBlock(collectionView.reloadData)
    
    0 讨论(0)
  • 2020-11-27 11:47

    Force this on the main thread:

    dispatch_async(dispatch_get_main_queue(), ^ {
        [self.collectionView reloadData];
    });
    
    0 讨论(0)
  • 2020-11-27 11:51

    It happened with me too in iOS 8.1 sdk, but I got it correct when I noticed that even after updating the datasource the method numberOfItemsInSection: was not returning the new count of items. I updated the count and got it working.

    0 讨论(0)
  • 2020-11-27 11:52

    Here is how it worked for me in Swift 4

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    
    let cell = campaignsCollection.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell
    
    cell.updateCell()
    
        // TO UPDATE CELLVIEWS ACCORDINGLY WHEN DATA CHANGES
        DispatchQueue.main.async {
            self.campaignsCollection.reloadData()
        }
    
        return cell
    }
    
    0 讨论(0)
提交回复
热议问题