Quick Tip #1: Fade Selected UITableViewCell

The iPhone/iTouch Contacts app has a very cool feature. Once you have tapped on a contact, the application highlights the contact’s name and then navigates to the contact’s details. When you hit the “All Contacts” button to return to the main view of the application, the UITableViewCell that was selected fades from blue to white. Neat!

GIVE ME THE CODE!

Here’s how it’s done. Add the code below to your UITableViewController. That’s it. That’s all.

-(void)viewDidAppear: (BOOL)animated
{
  [super viewDidAppear:animated];
  NSIndexPath *indexPath = [self.tableView 
     indexPathForSelectedRow];

  if(indexPath != nil)
  {
    [self.tableView deselectRowAtIndexPath:indexPath 
                                  animated:YES];
  }
}

SO HOW DOES IT WORK?

The method first gets the indexPath of the selected UITableViewCell. If ensures that a cell was “actually” selected and if so, it deselects the row. The magic (of the fading) happens because we set animated to YES!

As always, let me know if this helps. Drop me a comment or ping me on twitter www.twitter.com/haroldcampbell

-H

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: