Iphone 与UICollectionView混淆

Iphone 与UICollectionView混淆,iphone,uicollectionview,uicollectionviewcell,Iphone,Uicollectionview,Uicollectionviewcell,我是iOS编程的新手,我有一个UICollectionView方法,如下所示: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"Cell"; Cell *cell = [collectionView

我是iOS编程的新手,我有一个UICollectionView方法,如下所示:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

        static NSString *identifier = @"Cell";

        Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
        [cell mainImage].image =[UIImage imageNamed:[cellImages objectAtIndex:indexPath.row]];

        // WHATS HAPPEN AFTER TAP THE VIEW

        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
        singleTap.numberOfTapsRequired = 1;
        [cell mainImage].userInteractionEnabled = YES;
        [[cell mainImage] addGestureRecognizer:singleTap];
    //    cell.backgroundColor =[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"images-4.png]];

        return cell;
}
现在我想在这个方法中添加一个if;如果用户点击我数组中的最后一个图像,然后它调用一个新方法“addtapdetected”,并在我的集合视图中添加一个新单元格,现在我很困惑,不知道应该在哪里设置我的if和how?? 我知道我应该创建一个新的单元格,但不知道在哪里使用它…

首先更改

[cell mainImage].image =[UIImage imageNamed:[cellImages objectAtIndex:indexPath.row]];

在collectionview中,项目用于代替行

第二,如果您想在单元格点击时添加一个新的单元格,那么您应该将该单元格的代码放在这个方法中

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

在这种方法中,您不需要使用任何点击手势。它会自动检测单元格用户点击。

您只需执行-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView DidSelectCellatinex:(NSIndexPath*)indexPath即可,而无需添加点击手势。我想那是名字,然后检查id对象;如果(object==[array lastObject]]{[self addtapsected];}…希望可以用!并且有帮助:)
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath