有很多答案將圖像加載到UITableViews或UICollectionViews中。但是如果我的UICollectionView顯示來自其他視圖控制器的視圖呢?更快的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。 –