【发布时间】:2014-03-29 01:06:36
【问题描述】:
对于将图像加载到 UITableViews 或 UICollectionViews 有很多答案。但是如果我的 UICollectionView 正在显示来自其他视图控制器的视图怎么办?
在我的 UICollectionViewCell 子类中说我有这个:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.catViewController = [[CatViewController alloc] initWithNibName:nil bundle:nil];
self.catViewController.view.frame = self.bounds;
[self addSubview:self.catViewController.view];
}
return self;
}
在我的集合视图数据源中:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:kSomeId forIndexPath:indexPath];
cell.catViewController.data = self.data[indexPath.row]; //see below
return cell;
}
catViewController 有一个数据属性的设置器。设置此属性后,猫将加载它的图像以及该视图的其他一些相关图像。那么如何正确重用 MyCell 单元格,以便集合视图不会在每次创建(或重用)单元格时出现口吃?每个 MyCell 都占据了水平滚动的集合视图的整个宽度,因此每次新单元格滚动到视图中时,集合视图都会暂停片刻。
【问题讨论】:
-
如果设置单元格花费太多时间,您可能需要同时填充虚拟单元格,并将图像加载到数据设置器的完成块中。这样,当单元格加载后,您会看到单元格在占位符上方淡入,但滚动可以保持流畅。
-
我认为您需要发布在单元格的
catViewController上设置data时实际发生的情况。如何优化很大程度上取决于您在该方法中所做的工作。 -
也许你需要的是一个 PageViewController。
标签: ios uitableview asynchronous uicollectionview uicollectionviewcell