CollectionView,scrollToItemAtIndexPath方法失效

 

NSIndexPath *indexPath = [NSIndexPath indexPathWithIndex:2];
  [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:(UICollectionViewScrollPositionCenteredHorizontally) animated:NO];

indexPath获取方法更换为 

+ (instancetype)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
        [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:(UICollectionViewScrollPositionCenteredHorizontally) animated:NO];

问题就解决啦

你可能感兴趣的:(OC,ios)