失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Why does uitableview cell remain highlighted?

Why does uitableview cell remain highlighted?

时间:2024-02-12 09:29:51

相关推荐

Why does uitableview cell remain highlighted?

Why does uitableview cell remain highlighted?

What would 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 thedeselectRowAtIndexPathin my viewDidAppear, if select the row brings up a new view. – notnoop Dec 3 '09 at 15:59Actually 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 should not be needed... – Kendall Helmstetter Gelner Dec 3 '09 at 20:40@Kendall, @4thSpace: Maybe my last comment was confusing as to who I was referring to, apologies for that. UITableViewController calls the-deselectRowAtIndexPath:animated:method on its tableView property from-viewDidAppear. However, if you have a table view in a UIViewController subclass, you should call-deselectRowAtIndexPath:animated:from-viewDidAppearyourself. :) – Daniel Tull Dec 4 '09 at 12:19In my subclass of UITableViewController it was actually an override of-viewWillAppear:that broke it. Adding a call to[super viewWillAppear:animated]got it working again. – Ben Challenor Jul 6 '11 at 9:38Since 3.2, the automatic deselection behaviour occurs if yourUITableViewController'sclearsSelectionOnViewWillAppearproperty is set toYES(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 anyNSIndexPath* 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 should be.

Taken from /showthread.php?t=577677

/questions/1840614/why-does-uitableview-cell-remain-highlighted#comment1733845_1840757

posted on -07-09 08:59 罗斯摩根 阅读( ...) 评论( ...) 编辑 收藏

如果觉得《Why does uitableview cell remain highlighted?》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。