Differentiate Between UITableView Editing States?
- by Josh Kahane
I have been looking at trying to differentiate between editing states in my UITableView.
I need to call a method only when in editing mode after tapping the edit button, so when you get your cell slide in and you see the little circular delete icons but NOT when the user swipes to delete.
Is there anyway I can differentiate between the two?
Thanks.
EDIT:
Solution thanks to Rodrigo
Both each cell and the entire tableview has an 'editing' BOOL value, so I loop through all the cells and if more than one of them is editing then we know the whole table is (the user tapped the edit button), however if only one is editing then we know that the user has swiped a cell, editing that individual one, this lets me deal with each editing state individually!
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
int i = 0;
//When editing loop through cells and hide status image so it doesn't block delete controls. Fade back in when done editing.
for (customGuestCell *cell in self.tableView.visibleCells)
{
if (cell.isEditing) {
i += 1;
}
}
if (i > 1)
{
for (customGuestCell *cell in self.tableView.visibleCells)
{
if (editing)
{
// loop through the visible cells and animate their imageViews
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
cell.statusImg.alpha = 0;
[UIView commitAnimations];
}
}
}
else if (!editing)
{
for (customGuestCell *cell in self.tableView.visibleCells)
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
cell.statusImg.alpha = 1.0;
[UIView commitAnimations];
}
}
}