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. css3mediaquery移动端网页字体适应屏幕代码

    @media screen and (min-width:320px) and (max-width:321px) { html { font-size: 62.5%; } } @media scre ...

  2. WPF拖动DataGrid中的数据到ListBox

    1.效果图: 2.XAML <Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.m ...

  3. Python之路【第二篇】:Python基础(一)

    一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. 1 2 3 if 1==1:     name = 'wupeiqi' print  name 下面的结论对吗? ...

  4. 查看cics 运行状态

     查看cics 运行状态cicscp -v status all 

  5. [转载]《C++0x漫谈》系列之:多线程内存模型

    <C++0x漫谈>系列之:多线程内存模型 By 刘未鹏(pongba) 刘言|C++的罗浮宫(http://blog.csdn.net/pongba) <C++0x漫谈>系列导 ...

  6. CentOS学习笔记--JDK安装

    JDK安装 大部分的服务都离不开JAVA环境,CentOS里都是OpenJDK,显然我们还是使用JAVA的JDK好.(注:minimal版没有安装OpenJDK,其它版本需要删除这个.) JDK下载 ...

  7. 如何在某个按钮上触发 bootstarp Modal 组件

    <?php Modal::begin([ 'id'=>'myModal', 'header' => '<h2>标题</h2>']); echo '内容'; M ...

  8. Web 应用程序项目 MvcApplication1 已配置为使用 IIS。

    今天网上下了一个项目,加载不了,并报如下错误: Web 应用程序项目 MvcApplication1 已配置为使用 IIS. 若要访问本地 IIS 网站,必须在管理员帐户的上下文中运行 Visual ...

  9. 新浪SAE URLRewrite(伪静态、重定向)详解

    SAE全称Sina App Engine,真是一个好东西,他有很多优秀的特性,简单来说SAE就是一个简单高效的分布式Web服务开发.运行平台.支持现在常用的 PHP+Mysql 环境,在开发中难免会碰 ...

  10. VLC 重新编译第三方库的预编译包contrib

    VLC的引用了很多开源的第三方库,均放到VLC目录下的contrib中(本来开始编译是2.1.x以上版本,以前或以后可能会变化),在Windows版本编译中,contrib文件夹中仅仅下载VLC官网上 ...