UICollectionViewController编辑

时间:2012-09-24 15:15:24

标签: ios6 uicollectionview

我可以通过按导航面板上的编辑按钮,使用self.navigationItem.leftBarButtonItem = self.editButtonItem;使UITableViewController处于可编辑状态。

如何为UICollectionViewController制作此类行为?

1 个答案:

答案 0 :(得分:4)

<强>解决方案:

我添加了删除图像的按钮到单元格, 然后在cellForItemAtIndexPath:

...
if (self.editing) {
    cell.deleteButton.hidden = NO;
}else cell.deleteButton.hidden = YES;
...

在编辑按钮触摸时重新加载数据:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    _fetchedResultsController = nil;
    [self.collectionView reloadData];
}

按钮触发删除方法:

- (IBAction)deleteTour:(UIButton *)sender{
    NSIndexPath *indexPath = nil;
    indexPath = [self.collectionView indexPathForItemAtPoint:[self.collectionView convertPoint:sender.center fromView:sender.superview]];
}