Friday, July 16, 2010

Deselecting UITableViewCell's when a view appears

Here's a simple tip to make your application look a little more polished. It's very common for us to push new view controllers when a row is selected in a UITableView. If the user uses a UINavigationBar button to go back to the previous view, or the new view controller gets popped in some other manner, you will want to remove the highlight from the selected UITableViewCell. Here's a simple snippet to add to do just that assuming you have a UITableView that is an IBOutlet on your view controller:

- (void) viewDidAppear:(BOOL)animated {
if ([self.table indexPathForSelectedRow]) {
[self.table deselectRowAtIndexPath:[self.table indexPathForSelectedRow] animated:YES];
}
}

No comments:

Post a Comment