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 the deselectRowAtIndexPath in my viewDidAppear, if select the row brings up a new view. –  notnoop Dec 3 ‘09 at 15:59

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 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 -viewDidAppear yourself. :) –  Daniel Tull Dec 4 ‘09 at 12:19

In 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:38

Since 3.2, the automatic deselection behaviour occurs if your UITableViewController‘s clearsSelectionOnViewWillAppear property is set to 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 should be.

Taken from http://forums.macrumors.com/showthread.php?t=577677

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

Why does uitableview cell remain highlighted?,布布扣,bubuko.com

时间: 2024-10-11 23:18:14

Why does uitableview cell remain highlighted?的相关文章

IOS 8 UITableView cell lines不能靠左解决方法

ios7中用以下方法可使UITableView cell lines靠左 self.tableview.separatorInset = UIEdgeInsetsZero; 但在ios8中该办法已失灵啦 经过翻阅ios8文档发现用以下两种办法即可解决该问题 方法一:- (void) viewDidLoad { [...] self.tableView.separatorInset = UIEdgeInsetsZero; if ([self.tableView respondsToSelector

UITableView Cell 弹簧动画效果

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.transform = CGAffineTransformMakeTranslation(0, 40); [UIView animateWithDuration:0.8 animations:^{ cell.transform = C

UITableview cell 的多选

利用NSMutableDictionary  key值 来改变cell的状态 -(void)createUI{ table = [[UITableView alloc]initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/2.0) style:UITableViewStylePlain];    [table setSep

UITableView cell中label自动换行和自定义label自动换行

换行的前提必须是有足够的高度 才能换 否则不显示超出部分 所以,在设置label换行的时候 要考虑cell的高度,cell的高度也要变化,废话不多说,来段代码: cell.label.text=[dict objectForKey:@"info"];     cell.label.numberOfLines=0; //可多行显示     cell.label.lineBreakMode=NSLineBreakByWordWrapping;//拆行 设置label的高度 [self ch

优化UITableView cell的滚动速度

1. 利用好instruments.先检测leaks,再去观察优化效果. 2. 重中之重在于tableview cell的初始化,建议在tableview delegate中只实现配置方法,渲染全扔到drawInRect中做. 3. 中心思想,instruments core animation的上下两栏 Core Animation的帧率在60FPS以上,但是保持稳定也很重要 Sampler栏,不要让坡度变化太大,尽量平稳且低,在wwdc中提过.上面帧频自然越高越好. 利用reuse来循环利用

【iOS】UITableview cell 顶部空白的n种设置方法

我知道没人会主动设置这个东西,但是大家一定都遇到过这个问题,下面总结下可能是哪些情况: 1, self.automaticallyAdjustsScrollViewInsets = NO; 这个应该是最常见而且不容易被发现的原因,起因是iOS7在Conttoller中新增了automaticallyAdjustsScrollViewInsets这个属性,当设置为YES时(默认YES),如果视图里面存在唯一一个UIScrollView或其子类View,那么它会自动设置相应的内边距,这样可以让scr

iOS - UITableView 编辑(cell的插入, 删除, 移动)

UITableView Cell的插入/删除 核心API Class : UITableView Delegate : UITableViewDataSource, UITableViewDelegate 涉及的API:(API的官方详细注释详见本章结尾) /** TableView 进入或退出编辑状态(TableView 方法). */ - (void)setEditing:(BOOL)editing animated:(BOOL)animate /** 确定哪些行的cell可以编辑 (UIT

iOS开发总结-UITableView 自定义cell和动态计算cell的高度

UITableView cell自定义头文件: shopCell.h #import <UIKit/UIKit.h> @interface shopCell : UITableViewCell @property (strong, nonatomic)  UIImageView *image;@property (strong, nonatomic)  UILabel *name;@property (strong, nonatomic)  UILabel *itemshop;@propert

UITableView -registerClass:forCellReuseIdentifier:

In iOS 6, 2 new methods -registerClass:forCellReuseIdentifier: and -dequeueReusableCellWithIdentifier:forIndexPath: were added to UITableView. Prior to this, you would write code like the following when you need a UITableView cell instance: - (UITabl