如何获取位于 UICollectionView 中心的单元格的 indexPath [英] how to get indexPath for cell which is located in the center of UICollectionView
问题描述
如何在 UICollectionView
中间找到 cell
的 indexPath
?
How can i find indexPath
for cell
in the middle of UICollectionView
?
我有水平滚动,只有一个大的 cell
是可见的(侧面的另外两个 cell
也是可见的).我需要删除位于中心的 cell
(意味着 - 当前 cell
)而不触摸它.
I have horizontal scrolling and only one big cell
is visible (partially two other cell
s on the sides are visible as well).
I need to delete cell
located in the center (means - current cell
) without touching it.
仅按垃圾箱"按钮并确认删除.但现在它只删除第一个 cell
s.
Only pressing "Trash" button and confirm Delete. But now it delete only first cell
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'",[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];
}
}
推荐答案
就像你自己做的那样,indexPathForItemAtPoint
是找到你感兴趣的元素的索引路径的好方法.如果你问题是:我怎么知道这个点的坐标?然后您应该尝试使用(使用您在代码片段中给出的相同名称):
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屋!