вот вызов для всех вас ...UICollectionView занимает много времени, чтобы обновить данные
У меня есть 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
wit 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;
}
Вы должны использовать Инструменты и Профайлер времени, чтобы определить, где тратится время. –
Ну, Time Profiler говорит, что проблема здесь: UserPhotoCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier: @ «userPhotoCell» forIndexPath: indexPath]; ... ReusableCell ... возможно, я должен включить «if (cell == nil)», ? –