我有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