Why does uitableview Cell remain highlighted?

Source: Internet
Author: User

What wowould cause a tableview cell to remain highlighted after being touched? I click the cell and can see it stays highlighted as a Detail View is pushed. Once the Detail View is popped, the cell is still highlighted.

#######

In your didselectrowatindexpath you need to call deselectrowatindexpath to deselect the cell.

So whatever else you are doing in didselectrowatindexpath you just have it call deselectrowatindexpath as well.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Do some stuff when the row is selected [tableView deselectRowAtIndexPath:indexPath animated:YES];}
I prefer calling deselectRowAtIndexPathIn my viewdidappear, if select the row brings up a new view. -notnoop Dec 3 '09 at actually that is not the right place to call it, really... try using an Apple App with tables (contacts is a good one) and you'll see after you push out to a new screen, on return the cell is still highlighted briefly before being deselected. in theory I think you do not have to do any extra work to have it deselect right away on its own, so code in viewdidappear shoshould not be needed... -Kendall helmstetter Gelner dec 3'09 at 20:40 @ Kendall, @ 4 thspace: Maybe my last comment was confusing as to who I was referring to, apologies for that. uitableviewcontroller cballs -deselectRowAtIndexPath:animated:Method on its tableview property from -viewDidAppear. However, if you have a table view in a uiviewcontroller subclass, you showould call -deselectRowAtIndexPath:animated:From -viewDidAppearYourself. :)-Daniel Tull dec 4'09 at in my subclass of uitableviewcontroller it was actually an override -viewWillAppear:That broke it. Adding a call [super viewWillAppear:animated]Got it working again.-Ben Challenor Jul 6 '11 at since 3.2, the automatic deselection behaviour occurs if your UITableViewController'S clearsSelectionOnViewWillAppearProperty is set YES(Which is the default), and you haven't prevented [super viewWillAppear]From being called.-defragged Oct 31 '11 at 10: 26 the most clean way to do it is on viewwillappear:
- (void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    // Unselect the selected row if any    NSIndexPath*    selection = [self.tableView indexPathForSelectedRow];    if (selection) {        [self.tableView deselectRowAtIndexPath:selection animated:YES];    }}

This way you have the animation of fading out the selection when you return to the Controller, as it shoshould be.

From http://forums.macrumors.com/showthread.php? T = 577677

 

Http://stackoverflow.com/questions/1840614/why-does-uitableview-cell-remain-highlighted#comment1733845_1840757

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.