2015-07-05 2 views
0

У меня есть массив, содержащий разные изображения, в которые я добавляю CollectionView с помощью метода cellForItemAtIndexPath, и я пытаюсь использовать метод «didSelectItemAtIndexPath», чтобы определить, является ли выбранная ячейка последней, но я могу похоже, все правильно. Любая помощь будет оценена! Вот мой метод:Как выбрать последнюю ячейку в CollectionView?

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

UICollectionViewCell *cell =[collectionView cellForItemAtIndexPath:indexPath]; 
    if(cell == [PicArray lastObject]) 
    { 
    NSLog(@"selected last cell"); 
    } 

} 

ответ

0

Я понял. (count - количество объектов в массиве).

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

NSIndexPath *indexPath2 = [NSIndexPath indexPathForItem:(int)count inSection:0]; 

if([indexPath isEqual:indexPath2]) 
    { 
    UICollectionViewCell *cell =[collectionView cellForItemAtIndexPath:indexPath]; 
    NSLog(@"selected last cell"); 
    } 
} 
+0

у вас есть "от от 1" Ошибка здесь – almas

0

Что я использую это UICollectionView метод inbuild

override func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) { 
     if indexPath.row == dataSource.count - 1 { 
      // Last cell is visible 
      if self.pagination.has_more { 
       fetchFeeds() 
      } 
     } 

}

2
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 
    if ([indexPath.item == PicsArray.count-1]) { 
     NSLog(@"selected last cell"); 
    } 
}