Reloading UICollectionView causing flickering

I have subclassed a CollectionView and using it using to display a collection of images in different categories. For example: Most Popular, Most Viewed. I access each category/page through a TabbarController.

The classes I have are:

  • Implementing SimpleFTPSample in swift
  • Objective C - get the following day from today (tomorrow)
  • Xcode C++ and Objective-C refactoring
  • Access UI elements in UITableView section header
  • App crash when add Google Conversion Tracking SDK iOS-3.0.0
  • Exclude Files/Lines of code in Xcode 7 Code Coverage
  • Main class – MediaList – Base class for fetching and displaying media in a collection view depending on what type of media is requested.

    SubClasses – MostPopular and MostViewed are both very light classes that inherit from the main class.

    The problem is that when I move from MostPopular to MostViewed, the collection view initially displays the last category of pictures and then refreshes to the new…As a result you see a flicking effect.

    Sample code from MediaList

    - (void)viewDidLoad
        [super viewDidLoad];
        self.mediaCollection.dataSource = self;
        self.mediaCollection.delegate = self;
        [self getMedia];
    (void) getMedia 
        NSLog(@"/////////////////////////   GETTING MEDIA  /////////////////////////");
        XMLGenerator * sharedXmlGen = [XMLGenerator sharedXmlGenerator];
        GlobalVars * sharedGlobalVars = [GlobalVars sharedGlobalVars];
        sharedXmlGen.assetFlag = _contentFilter;
        NSLog(@"The filter is: %@", _contentFilter);
        [sharedXmlGen getPhotoVideoWithCallBackFunction:^{
        [_mediaCollection performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];

    Sample code from SubClass (MostPopular):

    - (void)viewDidLoad
        [super setContentFilter:FILTER_POPULAR];  //Set the filter for the type of content
        [super viewDidLoad];
    // Do any additional setup after loading the view.

    Two clarifications:

    1. I should add that I am trying to re-use as much code as possible without having to create new views on the storyboard or controllers.

    2. Because the media returned is very dynamic and can be updated regularly, I have had to reload my data (using getMedia) on viewDidAppear. This now means each selection of a particular page will result in the flickering when the new view is loaded…

    – After further investigation it looks like this has nothing to do with subclassing the uicollectionview. The issue instead is just reloading data into the uicollectionview. To be sure, I just clicked on one of the two subclassed views. I also added a reload method to the viewdidAppear method just to see the issue get even worse. It’s also much easier to see that the issue is that last set of images in the collection view initially displays the last category of pictures before the new one refreshes. Then once the collection is refreshed I get the flicker.

    *Updates Oct 4 *
    Starting to think my best solution is to display a waiting indicator and block the page while loading. I did try setting the uicollectionview to nil, and believe that will solve the problem as well, but not sure it will be straightforward to reset.

    Solutions Collect From Internet About “Reloading UICollectionView causing flickering”

    Although it may not be immediately apparent in the code above the root cause was actually the getMedia call. All of the subclassing etc. works perfectly fine.

    Specifically having the reload method in the getMedia call and was creating the issue.

    [_mediaCollection performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];