[英]How to select the last cell in a CollectionView?
我有一個包含不同圖像的數組,其中使用“ cellForItemAtIndexPath”方法將其添加到CollectionView中,並且嘗試使用“ didSelectItemAtIndexPath”方法來確定所選單元格是否為最后一個,但是我似乎可以修正它。 任何幫助,將不勝感激! 這是我的方法:
-(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");
}
}
我想到了。 (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");
}
}
我正在使用的是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.