【问题标题】:UITableview tablecell separator missing when the tablecell is selected programatically以编程方式选择表格单元格时缺少 UITableview 表格单元格分隔符
【发布时间】:2014-03-28 21:29:37
【问题描述】:
@implementation TestTableViewCell

-(void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    self.selectedBackgroundView = [[UIView alloc] init];
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    [super setHighlighted:highlighted animated:animated];
    if(highlighted || self.selected)
    {
        self.labelTest.tintColor = self.tintColor;
        self.labelTest.text = @"HighLighted";
    }
    else
    {
        self.labelTest.tintColor = [UIColor redColor];
        self.labelTest.text = @"Not HighLighted";
    }


}


@end

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    tableView.separatorColor = [UIColor redColor];
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testCell"];

    if (indexPath.row == 5) {
        [tableView selectRowAtIndexPath:indexPath animated:NO    scrollPosition:UITableViewScrollPositionNone];

    }

    return cell;
}

这是我的代码。如果行是 5 以编程方式使用 selectRowAtIndexPath 选择单元格。当我这样做时,7.1 中缺少表格分隔符但相同的代码在 7.0 中工作正常

不确定为什么 7.1 中缺少分隔符

【问题讨论】:

  • 这听起来类似于这个问题。听起来单元格正在分隔符的顶部绘制。您可以尝试调整单元格的高度。 stackoverflow.com/questions/22358831/…
  • @DaveS 我在发布问题之前尝试过。不幸的是,这对我不起作用。感谢您的调查。
  • self.selectedBackgroundView = [[UIView alloc] init];在我看来也很可疑。为什么选择时使用空白视图作为背景?从您的图片来看,它看起来没有必要,如果分隔符在背景视图中,它将解释缺少分隔符。
  • 问题是视图覆盖了分隔符,只需确保为 heightForRowAtIndexPath 方法返回正确的高度,并确保在运行时没有更改视图高度
  • 我正在使用自定义的 uitableviewcell。我没有动态改变高度。

标签: ios ios7 uitableview ios7.1


【解决方案1】:

实际上问题在于设置选定的背景。它在 iOS7 中运行良好,但在 7.1 中存在一些问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 2014-03-19
    • 2013-07-08
    • 2011-09-04
    相关资源
    最近更新 更多