UITableView 自定义分隔符,选择时隐藏

Posted

技术标签:

【中文标题】UITableView 自定义分隔符,选择时隐藏【英文标题】:UITableView custom separator, hidding when selecting 【发布时间】:2012-04-17 10:47:37 【问题描述】:

我有一个快速的问题。我有一个UITableViewController,其中包含自定义分隔符的自定义单元格(作为UIImageView,它是cell.contentView 的子视图)。现在,当我选择一个单元格时,我想隐藏我的分隔符,这样它就不会在我突出显示的背景上可见。

我试图使用这样的结构:

self.separatorImageViewTop.frame = CGRectMake(-240, 0, 120, 2);        

self.separatorImageViewTop.hidden = YES;

self.separatorImageViewTop.alpha = 0;

[self.separatorImageViewTop.frame removeFromSuperview]

Each of this ways is working but each of them is making a blinking effect on custom separator when cell is selected.如何避免这种闪烁效果?

我的代码是从以下位置调用的:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

但我尝试过使用:

-(NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

希望在tableView:willSelectRowAtIndexPath: method, but the result are the same - still blinking effect of a disapearingUIImageView`之后实际突出显示单元格。

有什么想法吗?

【问题讨论】:

【参考方案1】:

尝试在您的自定义单元格中覆盖此方法:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state

【讨论】:

以上是关于UITableView 自定义分隔符,选择时隐藏的主要内容,如果未能解决你的问题,请参考以下文章