我有一个集合看法,我试图删除集合视图细胞上didSelect method.I成功,使用下面的方法
[colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
但现在我需要删除的CollectionView Cell.Here我只得到了indexpath.row按钮单击该项目。 从这个我不能删除的项目。 我想是这样的。
-(void)remove:(int)i {
NSLog(@"index path%d",i);
[array removeObjectAtIndex:i];
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:i inSection:0];
[colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
[colleVIew reloadData];
}
但它需要重新加载CollectionView.So细胞排列的动画后删除不存在。 请建议提前一个idea..thanks
-(void)remove:(int)i {
[self.collectionObj performBatchUpdates:^{
[array removeObjectAtIndex:i];
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:i inSection:0];
[self.collectionObj deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
} completion:^(BOOL finished) {
}];
}
试试这个。 它可能为你工作。
斯威夫特3解决方案:
func remove(_ i: Int) {
myObjectsList.remove(at: i)
let indexPath = IndexPath(row: i, section: 0)
self.collectionView.performBatchUpdates({
self.collectionView.deleteItems(at: [indexPath])
}) { (finished) in
self.collectionView.reloadItems(at: self.collectionView.indexPathsForVisibleItems)
}
}
和示例删除通话:
self.remove(indexPath.row)
SWIFT 3:
func remove(index: Int) {
myObjectList.remove(at: index)
let indexPath = IndexPath(row: index, section: 0)
collectionView.performBatchUpdates({
self.collectionView.deleteItems(at: [indexPath])
}, completion: {
(finished: Bool) in
self.collectionView.reloadItems(at: self.collectionView.indexPathsForVisibleItems)
})
}
[array removeObjectAtIndex:[indexPath row]];
[collection reloadData]; // Collection is UICollectionView
试试这个。
[array removeObjectAtIndex:[indexPath row]];
[self.collectionView deleteItemsAtIndexPaths:@[indexPath]];
通常它是确定......你可以看到这篇文章 ,它与相同主题的交易。
我得到了答案..
创建CollectionViewCell一个按钮//我把它命名为removeBtn
然后,在委托的CollectionView
- cellForItemAtIndexPath
[cell.removeBtn addTarget:self action:@selector(RemovePrssd:) forControlEvents:UIControlEventTouchUpInside];
然后添加方法
-(void)RemovePrssd:(id)sender{
UIView *senderButton = (UIView*) sender;
NSIndexPath *indexPath = [colleVIew indexPathForCell: (UICollectionViewCell *)[[senderButton superview]superview]];
[array removeObjectAtIndex:indexPath.row];
[colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
}