I have a UITableView with two sections (a top section and a bottom section). When items are "checked off" in the top section (section 0), I'm moving them them to the bottom section (section 1) and vice versa. Everything is working great save for the animation.
I'm using the following, but the row movement is sluggish - I've seen better results in other apps. I'd like the rows from the top section to animate cleanly to the bottom section ... and the rows from the bottom section to animate cleanly to the top section when they are checked or unchecked.
// set the guests arrival status and use animation
[guestList beginUpdates];
if (!guest.didArrive) {
[guest setDidArrive:YES];
[guestList reloadSections:sectionIndexSet withRowAnimation:UITableViewRowAnimationBottom];
} else {
[guest setDidArrive:NO];
[guestList reloadSections:sectionIndexSet withRowAnimation:UITableViewRowAnimationTop];
}
[guestList endUpdates];
[guestList reloadData];
How should I code this for nice smooth animation?
Edit:
I found the problem. The could should be written this way instead:
//NSIndexSet *sectionIndexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];
// set the guests arrival status and use animation
[guestList beginUpdates];
if (!guest.didArrive) {
[guest setDidArrive:YES];
[guestList reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationBottom];
} else {
[guest setDidArrive:NO];
[guestList reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationTop];
}
[guestList endUpdates];
[guestList reloadData];
Note the first line that I commented out. I neglected to add this originally. As you can see, I was using a poorly constructed NSIndexSet.
Problem solved. Please see edited response. Code should be:
// set the guests arrival status and use animation
[guestList beginUpdates];
if (!guest.didArrive) {
[guest setDidArrive:YES];
[guestList reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationBottom];
} else {
[guest setDidArrive:NO];
[guestList reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationTop];
}
[guestList endUpdates];
[guestList reloadData];