我如何知道UICollectionView已经完全加载? [英] How do I know that the UICollectionView has been loaded completely?

查看:847
本文介绍了我如何知道UICollectionView已经完全加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当UICollectionView被完全加载时,我必须做一些操作,即当时应该调用所有的UICollectionView的数据源/布局方法。我怎么知道?有没有任何代理方法来知道UICollectionView加载状态?

解决方案

  //在viewDidLoad 
[self.collectionView addObserver:self forKeyPath:@contentSize选项:NSKeyValueObservingOptionOld上下文:NULL];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)更改上下文:(void *)context
{
//当reloadData完成
}

- (void)dealloc
{
[self.collectionView removeObserver:self forKeyPath:@contentSizecontext:空值];
}


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?

解决方案

// 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];
}

这篇关于我如何知道UICollectionView已经完全加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆