I have a UITableView with two sections (top and bottom). When items are “marked” at the top (section 0), I move them to the bottom (section 1) and vice versa. Everything works fine except for the animation.
I use the following, but the string movement is sluggish - I have seen better results in other applications. I would like the lines from the top to be well animated at the bottom ... and the lines from the bottom so that they are completely cleared to the top when they are marked or not marked.
// 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 do I encode this for a nice smooth animation?
Edit:
I found a problem. Instead, it could be written:
//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];
Pay attention to the first line that I commented on. I forgot to add this initially. As you can see, I used a poorly designed NSIndexSet.
source share