[英]How to select the last cell in a CollectionView?
I have an array that contains different images in which i am adding to the CollectionView with the "cellForItemAtIndexPath" method, and I am trying to use the "didSelectItemAtIndexPath" method to determine if the selected cell is the last one, but I can seem to get it right. 我有一个包含不同图像的数组,其中使用“ cellForItemAtIndexPath”方法将其添加到CollectionView中,并且尝试使用“ didSelectItemAtIndexPath”方法来确定所选单元格是否为最后一个,但是我似乎可以修正它。 Any help would be appreciated! 任何帮助,将不胜感激! Here is my method: 这是我的方法:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell =[collectionView cellForItemAtIndexPath:indexPath];
if(cell == [PicArray lastObject])
{
NSLog(@"selected last cell");
}
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath.item == PicsArray.count-1]) {
NSLog(@"selected last cell");
}
}
I figured it out. 我想到了。 (count is a count of the objects in the array). (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");
}
}
What i am using is UICollectionView inbuild method 我正在使用的是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()
}
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.