UICollectionView selectItemAtIndexPath doesn't call didSelectItemAtIndexPath

后端 未结 4 1942
眼角桃花
眼角桃花 2021-02-07 12:22

I have a collection view. I would like to programmatically select a cell. This is the code I use

[_collectionView selectItemAtIndexPath:[NSIndexPath indexPathFor         


        
相关标签:
4条回答
  • 2021-02-07 12:28

    You can make it.

    [self.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
    [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
    

    if use only selectItemAtIndexPath:animated:scrollPosition: method, don't call delegate method. if use only collectionView:didSelectItemAtIndexPath: method, it don't work stabil

    happy code :)

    0 讨论(0)
  • 2021-02-07 12:43

    Yes, this is proper behaviour. Documentation for [selectItemAtIndexPath:animated:scrollPosition:] says:

    This method does not cause any selection-related delegate methods to be called.

    0 讨论(0)
  • 2021-02-07 12:47

    Osmenda's answer in Swift with my custom collection view:

    self.collectionView(calendarCV, didSelectItemAtIndexPath: indexPath)
    
    0 讨论(0)
  • 2021-02-07 12:51

    Swift 4:

    self.collectionView(daysCollectionView, didSelectItemAt: indexPath)
    
    0 讨论(0)
提交回复
热议问题