Я хочу разрешить пользователю выбирать только одну ячейку & данные будут отражаться на этом основании. (поэтому одновременно будет выбрана только одна ячейка.), но вместо этого, если я быстро нажимаю несколько пальцев, я могу выбрать несколько ячеек в определенное время.Collectionview single selection
Я сделал это с didSelectItemAtIndexPath
& didDeselectItemAtIndexPath
также, но в этом случае я не могу выбрать.
Может ли кто-нибудь помочь в этой функции?
Вот пример кода, который я использую: -
[CustomCollection setShowsHorizontalScrollIndicator:NO];
[CustomCollection setBounces:NO];
[CustomCollection setAllowsMultipleSelection:NO];
[CustomCollection setMultipleTouchEnabled:NO];
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"TheCustomCell";
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
if (previousIndexPath.row == indexPath.row) {
// Code for Selecttion
[cell.tickImgView setImage:[UIImage imageNamed:@"Select_tick"]];
}
else{
[cell.tickImgView setImage:[UIImage imageNamed:@"Deselect_tick"]];
}
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
dispatch_async(dispatch_get_main_queue(), ^{
previousIndexPath = indexPath;
[CustomCollection reloadData];
});
}
http://stackoverflow.com/questions/34614815/how-to-disable-multiple-touch-on-a-uicollectionview –
@ManishPathak Я пробовал этот способ, но он все еще выбирает несколько ячеек. –
Требуется перезагрузка коллекцииView при каждом выборе элемента. –