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?的更多相关文章

  1. UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题

    UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...

  2. UITableview cell 的多选

    利用NSMutableDictionary  key值 来改变cell的状态 -(void)createUI{ table = [[UITableView alloc]initWithFrame:CG ...

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

    换行的前提必须是有足够的高度 才能换 否则不显示超出部分 所以,在设置label换行的时候 要考虑cell的高度,cell的高度也要变化,废话不多说,来段代码: cell.label.text=[di ...

  4. UITableView Cell 弹簧动画效果

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath ...

  5. Swift - UIView,UItableView,Cell设置边框方法

    // 设置边框的宽度 cell.layer.borderWidth = 1 // 设置边框的颜色 cell.layer.borderColor = UIColor.blackColor().CGCol ...

  6. UITableview cell中多个按钮

    xib的 //不使用这种- (IBAction)button:(UIButton *)sender; //使用这种 @property (weak, nonatomic) IBOutlet UIBut ...

  7. UITableView cell 半透明效果,改变cell高度时背景不闪的解决方法

    如果直接指定cell.backgroundColor = = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 ...

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

    我知道没人会主动设置这个东西,但是大家一定都遇到过这个问题,下面总结下可能是哪些情况: 1, self.automaticallyAdjustsScrollViewInsets = NO;  这个应该 ...

  9. IOS 7 UITableView cell lines不能靠左解决方法

    添加一句:[UITableViewappearance].separatorInset=UIEdgeInsetsZero; 就可以解决啦.

随机推荐

  1. my vimrc

    runtime! debian.vim "设置编码 ,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 ,ucs-bom,chinese "语言 ...

  2. mq队列管理器命令

    dspmq: 队列管理器显示 QMCIPSA-------队列管理器 runmqsc QMSAA  运行查找Q队列名 运行MQ命令 runmqsc QmgrName 如果是默认队列管理器,可以不带其名 ...

  3. 华为OJ—字符串排序(排序,忽略指定字符排序)

    http://career-oj.huawei.com/exam/ShowProblemInfo?id=2168 编写一个程序,将输入字符串中的字符按如下规则排序. 规则1:英文字母从A到Z排列,不区 ...

  4. 动态设置屏幕icon

    REPORT demo_dynpro_status_icons.     DATA value TYPE i VALUE 1.     DATA: status_icon TYPE icons-tex ...

  5. s3c6410_u-boot-2010.03移植

    开发环境: 开发板 FriendlyARM Tiny6410 主机 CentOS release 6.4 (Final) 参考: http://www.cnblogs.com/plinx/archiv ...

  6. Web前端代码规范与页面布局

    一.    规范目的: 为提高工作效率,便于后台人员添加功能及前端后期优化维护,输出高质量的文档,在网站建设中,使结构更加清晰,代码简明有序,有一个更好的前端架构,有利于SEO优化.   二.     ...

  7. 面向对象的 JavaScript

    面向对象的javascript 一.创建对象 创建对象的几种方式: var obj = {}; var obj = new Object(); var obj = Object.create(fath ...

  8. SequoiaDB(巨杉数据库)(社区版)安装配置使用图解

    SequoaiDB是一款新型企业级分布式非关系型数据库,提供了基于PC服务器的大规模集群数据平台.作为全球第一家企业级文档式 NoSQL分布式数据库,为用户提供了一个高扩展性.高可用性.高性能.易维护 ...

  9. TextView字符串波浪式跳动--第三方开源---JumpingBeans

    在github上有一个开源项目:JumpingBeans,其项目主页是:https://github.com/frakbot/JumpingBeans JumpingBeans将一个普通的Androi ...

  10. 1)C++对象大小计算

          C++对象的大小不同的编译器的实现是不一样的,以下仅讨论.net2003,其他编译的可能出现的结果以下也做了分析和猜测.在反推不同编译器实现的C++对象的大小时.对齐是一个很重要也容易被遗 ...