При вызове -reloadData
несколько раз, -collectionView:didSelectItemAtIndexPath:
или -collectionView:didDeselectItemAtIndexPath:
не вызывается.
(При вызове один или два раза метод вызывается правильно.)
Запуск -reloadData
не занимает много времени. Использование памяти или процессора также не занято.
Почему бывают случаи, когда -collectionView:didSelectItemAtIndexPath:
не называется?При вызове -reloadData, -collectionView: didSelectItemAtIndexPath: not called
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCollectionCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellIdentifier forIndexPath:indexPath];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"select %d", indexPath.item);
[collectionView reloadData];
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"deselect %d", indexPath.item);
[collectionView reloadData];
}
CustomCollectionCell.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
//
}
return self;
}
Зачем было '-collectionView: didSelectItemAtIndexPath:' вызываться, когда вы '-reloadData'? – Schemetrical
из-за изменения свойства ячейки и отражения изменения в ячейке путем вызова '-reloadData'. –
Да, но '-collectionView: didSelectItemAtIndexPath:' вызывается, когда пользователь удаляет ячейку. – Schemetrical