我正在使用以下代码删除CollectionViewCell:
- (void)deleteProjects:(NSNotification *)notification {
// Get the current project
NSString *currentProject = [[MyManager sharedManager] projectForDeletion];
[_objects removeObject:currentProject];
[_projectsCollectionView performBatchUpdates:^{
NSArray *selectedItemsIndexPaths = [_projectsCollectionView indexPathsForSelectedItems];
// Now delete the items from the collection view.
[_projectsCollectionView deleteItemsAtIndexPaths:selectedItemsIndexPaths];
} completion:nil];
// Subtract 1 from editedProjects
editedProjects = editedProjects - 1;
// Set deletedProject
deletedProject = currentProject;
// Delete the associated subjects if any
[self deleteAssociatedSubjects];
// Save the new objects
[[NSUserDefaults standardUserDefaults] setObject:_objects forKey:@"myProjects"];
}
供用户删除项目:
现在,如果用户选择2个单元格,他/她将收到通知,一次只能编辑1个 - 但项目仍然被“选中” - 导致删除删除无法编辑的项目而不是原来的。我该如何解决这个问题?
选择方法:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath: (NSIndexPath *)indexPath
{
}
谢谢!
答案 0 :(得分:0)
indexPathForSelectedItem看起来很麻烦。
你可以这样做来获取indexPath:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[test indexOfObject:currentProject] inSection:0];
[_objects removeObject:currentProject];
[_projectsCollectionView performBatchUpdates:^{
[_projectsCollectionView deleteItemsAtIndexPaths:@[indexPath]];
} completion:nil];
...