如何获取位于UICollectionView中心的单元格的indexPath [英] how to get indexPath for cell which is located in the center of UICollectionView

查看:542
本文介绍了如何获取位于UICollectionView中心的单元格的indexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 UICollectionView indexPath for cell c $ c>?



我有水平滚动,只有一个大的单元格可见(部分另外两个<$两侧的c $ c> cell 也是可见的。
我需要删除位于中心的 cell (表示 - 当前单元格)而不触及它。 / p>

仅按废纸篓按钮并确认删除。但现在它只删除第一个单元格 s。

   - (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if(buttonIndex == actionSheet.destructiveButtonIndex){
initialPinchPoint = ????????

self.tappedCellPath = [self.collectionView indexPathForItemAtPoint:initialPinchPoint];

Technique * technique = [arrayOfTechnique objectAtIndex:self.tappedCellPath.row];

[self deleteData:[NSString stringWithFormat:@DELETE FROM TECHNIQUES WHERE TECHNIQUENAME IS'%s',[technology.techniquename UTF8String]]];

[arrayOfTechnique removeObjectAtIndex:self.tappedCellPath.row];

// [arrayOfTechnique removeObjectAtIndex:[custom_layout]];
[self removeImage:technique.techniquename];

[self.collectionView performBatchUpdates:^ {
[self.collectionView deleteItemsAtIndexPaths:[NSArrayarrayWithObject:self.tappedCellPath]];
}完成:nil];

[self checkArrayCount];
}
}


解决方案

赞你自己做了, indexPathForItemAtPoint 是一个很好的方法来找到你感兴趣的元素的索引路径。如果你的问题是:我怎么知道这一点的坐标?然后你应该尝试(使用你在代码片段中给出的相同名称):

  initialPinchPoint = CGPointMake(self.collectionView .center.x + self.collectionView.contentOffset.x,
self.collectionView.center.y + self.collectionView.contentOffset.y);


How can i find indexPath for cell in the middle of UICollectionView?

I have horizontal scrolling and only one big cell is visible (partially two other cells on the sides are visible as well). I need to delete cell located in the center (means - current cell) without touching it.

Only pressing "Trash" button and confirm Delete. But now it delete only first cells.

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex == actionSheet.destructiveButtonIndex) { 
        initialPinchPoint = ????????

        self.tappedCellPath = [self.collectionView indexPathForItemAtPoint:initialPinchPoint];

        Technique *technique = [arrayOfTechnique objectAtIndex:self.tappedCellPath.row];

        [self deleteData:[NSString stringWithFormat:@"DELETE FROM TECHNIQUES WHERE TECHNIQUENAME IS '%s'",[technique.techniquename UTF8String]]];

        [arrayOfTechnique removeObjectAtIndex:self.tappedCellPath.row];

        //[arrayOfTechnique removeObjectAtIndex:[custom_layout ]];
        [self removeImage:technique.techniquename];

        [self.collectionView performBatchUpdates:^{
            [self.collectionView deleteItemsAtIndexPaths:[NSArrayarrayWithObject:self.tappedCellPath]];
         } completion:nil];

         [self checkArrayCount];
    }
}

解决方案

Like you did yourself, indexPathForItemAtPoint is a good way of finding the index path of the element you're interested in. If your question is: how do i know the coordinates of this point? Then you should try with (using the same name you gave it in your code snippet):

initialPinchPoint = CGPointMake(self.collectionView.center.x + self.collectionView.contentOffset.x, 
                                self.collectionView.center.y + self.collectionView.contentOffset.y);

这篇关于如何获取位于UICollectionView中心的单元格的indexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆