I just want the cell to briefly highlight either with a UIColor or a background image before animating back to the unselected state when a user taps the cell. I'm marking the cell with a star to show that it has been selected but would like the whole cell to highlight briefly just to show selection.
add this line in the didSelectRowAtIndexPath -
[tableView deselectRowAtIndexPath:indexPath animated:YES];
I think the answer provided is solid if you want to animate just one row in response to selection.
I was looking for a way to do this with multiple rows simultaneously and without selecting and deselecting the rows in response to touch. I did the following:
Created a method in my UITableViewController called "calloutCells":
- (void)calloutCells:(NSArray*)indexPaths
{
[UIView animateWithDuration:0.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^void() {
for (NSIndexPath* indexPath in indexPaths)
{
[[self.tableView cellForRowAtIndexPath:indexPath] setHighlighted:YES animated:YES];
}
}
completion:^(BOOL finished) {
for (NSIndexPath* indexPath in indexPaths)
{
[[self.tableView cellForRowAtIndexPath:indexPath] setHighlighted:NO animated:YES];
}
}];
}
Note that the duration and delay don't change the animation I've chosen since I'm using the built in animation on setHighlighted.
When I want to initiate the highlight/unhighlight animation from the UITableViewController, I can simultaneously highlight rows 3 and 4 of section 0 like this:
[self calloutCells:[NSArray arrayWithObjects:
[NSIndexPath indexPathForRow:3 inSection:0],
[NSIndexPath indexPathForRow:4 inSection:0], nil]];
Hope this helps someone else!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With