【发布时间】:2015-11-12 06:04:21
【问题描述】:
我的视图控制器中有这个:
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CellSubclass *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
cell.dataObjects = data;
return cell;
}
在我的 CellSubclass.m 中,我有:
- (id) initWithFrame:(CGRect)frame
{
// You can call initWithFrame: method here as our base constructor of the UIView super class
self = [super initWithFrame:frame];
if (self)
{
// call functions that need access to data but data is nil
}
return self;
}
所以在我的视图控制器的生命周期中,CellSubclass 在数据准备好之前立即被调用。是否有类似 viewWillAppear 的功能或我也可以传递数据的功能?如何从我的视图控制器调用除 initWithFrame 之外的函数?我可以通过其他方式传递数据吗?
谢谢。
【问题讨论】:
-
在完成块中使用 reloadCollectionView 方法听起来更好,该方法在您的数据获取完成时调用。
标签: ios objective-c uiviewcontroller uicollectionview uicollectionviewcell