这里是为大家的挑战......UICollectionView需要很长的时间来刷新数据
我有一个UICollectionView
我UIViewController
女巫内部正确加载。 我也有一个自定义UICollectionViewCell
职业女巫包含一个UIButton
。
我为了一个背景图像分配给我的自定义UICollectionViewCell
的按钮来检索从我的一些UIImage
对象服务器NSArray
。
这是我的cellForItemAtIndexPath
函数的代码:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
UserPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"userPhotoCell" forIndexPath:indexPath];
if (indexPath.section == 0) {
[[cell imageButton] setBackgroundImage:[userPublicImages objectAtIndex:indexPath.row] forState:UIControlStateNormal];
} else {
[[cell imageButton] setBackgroundImage:[userPrivateImages objectAtIndex:indexPath.row] forState:UIControlStateNormal];
}
return cell;
}
正如你所看到的是很简单的。
来了奇怪的行为:如果我把我所有的自定义UICollectionViewCell
在UICollectionView
只是一个部分,其性能是好的...
什么想法?
一些额外的信息:UICollectionView
有标题。自定义标题。此时此刻UIView
就是UILabel
。
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableView = nil;
if (kind == UICollectionElementKindSectionHeader) {
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"collectionHeader" forIndexPath:indexPath];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [headerView frame].size.width, 40.0f)];
if (indexPath.section == 0) {
[titleLabel setText:NSLocalizedStringFromTable (@"collectionTitle_publicPhotos", [[NSLocale preferredLanguages] objectAtIndex:0] , @"")];
} else {
[titleLabel setText:NSLocalizedStringFromTable (@"collectionTitle_privatePhotos", [[NSLocale preferredLanguages] objectAtIndex:0] , @"")];
}
[headerView addSubview:titleLabel];
reusableView = headerView;
}
return reusableView;
}
您应该使用仪器和时间分析器来确定时间花在哪里。 – 2013-05-07 12:59:16
嗯,时间事件探查器说这个问题在这里:UserPhotoCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@“userPhotoCell”forIndexPath:indexPath]; ... reusableCell ...也许我应该包括“if(cell == nil)” ? – 2013-05-07 13:11:23