我有UICollectionView有两个UICollectionResuabeView(自定义视图)和一个UICollectionViewCell。 UICollectionView中的单个实体形式。我把删除按钮上的UICollectionResuabeView之一,并按下它想要删除行(如果我打电话的权利)。 这是屏幕截图的故事板: 如何删除行形式UICollectionView?
我试图让它的部分我的许多手段,但非工程。猜猜我对UICollectionView的工作原理没有足够的了解。这里是我尝试过的一些代码: 我知道它我混乱,但至少我试过))
我试过这个来获取indexPath,但没有任何作品。 - (IBAction为)deletePressed:(UIButton的*)发件人{
RecipeCollectionHeaderView *contentView = (RecipeCollectionHeaderView *)[sender superview];
RecipeViewCell *cell = (RecipeViewCell *)[contentView superview];
cell = (RecipeViewCell *)[contentView superview];
// determine indexpath for a specific cell in a uicollectionview
NSIndexPath *editPath = [self.collectionView indexPathForCell:cell];
NSInteger rowIndex = editPath.row;
NSInteger secIndex = editPath.section;
// NSIndexPath *indexPath = nil;
// indexPath = [self.collectionView indexPathForItemAtPoint:[self.collectionView convertPoint:sender.center fromView:sender.superview]];
// NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
// NSSet *touches = [event allTouches];
//
// UITouch *touch = [touches anyObject];
//
// CGPoint currentTouchPosition = [touch locationInView:self.collectionView];
//
// NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint: currentTouchPosition];
NSLog(@"IndexPath CollectionView %ld", (long)rowIndex);
}
我也试图使它像在这个岗位工作,但它没有给出一个结果:how to access from UICollectionViewCell the indexPath of the Cell in UICollectionView 谢谢大家!
编辑! 我发现这个效果很好:
-(IBAction)deletePressed:(UIButton*)sender{
[self.ordersArray removeObjectAtIndex:0];
[self.collectionView reloadData];
}
我现在唯一需要的是被按下的UIBotton,得到UICollectionView的部分删除部分我想要的。怎么办呢?)
你好,谢谢你的答复。似乎很好的答案。但我没有self.contentView属性。我知道这可能是一件愚蠢的事,但是你可以通过这个来引导我?)谢谢。 – sermilion 2015-02-23 08:06:48
self.contentView它是你的UiCollection视图 – 2015-02-23 08:08:58
只是一个小小的宠物尿道,它不是'UiCollection'它的'UICollectionView'记得很多初学者都依赖这个信息。不要把他们引向错误的道路。 – soulshined 2015-02-23 08:19:01