Search code examples
uicollectionviewdelegatesreload

How do I know that the UICollectionView has been loaded completely?


I have to do some operation whenever UICollectionView has been loaded completely, i.e. at that time all the UICollectionView's datasource / layout methods should be called. How do I know that?? Is there any delegate method to know UICollectionView loaded status?


Solution

  • // In viewDidLoad
    [self.collectionView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionOld context:NULL];
    
    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary  *)change context:(void *)context
    {
        // You will get here when the reloadData finished 
    }
    
    - (void)dealloc
    {
        [self.collectionView removeObserver:self forKeyPath:@"contentSize" context:NULL];
    }