14

コレクションビューがあります。プログラムでセルを選択したいと思います。これは私が使用するコードです

[_collectionView selectItemAtIndexPath:[NSIndexPath indexPathForItem:currentSelectedVideo inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionNone];

何らかの理由で機能:

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 

-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath

呼び出されないため、選択したセルを表示するために使用している視覚効果が画面に表示されません。

それは適切な行動ですか?

4

4 に答える 4

39

うまくいくよ。

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

selectItemAtIndexPath:animated:scrollPosition: メソッドのみを使用する場合は、デリゲート メソッドを呼び出さないでください。collectionView:didSelectItemAtIndexPath: メソッドのみを使用すると、安定して動作しません

ハッピーコード:)

于 2014-05-24T22:07:37.990 に答える