这是对你们所有人的挑战...
我有一个UICollectionView内部我的UIViewController女巫正在正确加载。我还有一个自定义UICollectionViewCell类女巫包含一个UIButton.
我NSArray从我的服务器中检索了一些UIImage对象,以便将一个背景图像分配给我的自定义按钮UICollectionViewCell。
这是我的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;
}