我有一个包含不同图像的数组,我在其中使用“cellForItemAtIndexPath”方法添加到CollectionView,我正在尝试使用“didSelectItemAtIndexPath”方法来确定所选单元格是否是最后一个,但是我似乎可以做对。任何帮助,将不胜感激!这是我的方法:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell =[collectionView cellForItemAtIndexPath:indexPath];
if(cell == [PicArray lastObject])
{
NSLog(@"selected last cell");
}
}
答案 0 :(得分:2)
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath.item == PicsArray.count-1]) {
NSLog(@"selected last cell");
}
}
答案 1 :(得分: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");
}
}
答案 2 :(得分: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()
}
}
}