【问题标题】:Strange behavoiur in UITableView - one cell displayed differentlyUITableView 中的奇怪行为 - 一个单元格显示不同
【发布时间】:2013-02-24 16:29:12
【问题描述】:

我的应用程序中的一个 UITableView 有问题。我将它设置为每个其他表格,但一个单元格始终具有白色背景而不是 [UIColor clearColor]。 这就是我实现tableView:cellForRowAtIndexPath:的方式:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdent = @"NewSessionCell";

    UITableViewCell *cell = [self.tableSubjects dequeueReusableCellWithIdentifier:cellIdent];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
    }

    [cell setAutoresizesSubviews:NO];
    [cell setBackgroundColor:[UIColor clearColor]];

    // set text color and font
    [cell.textLabel setTextColor:[UIColor whiteColor]];
    [cell.textLabel setFont:[UIFont systemFontOfSize:18.0]];

    // set clear background for selected cell
    UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
    backView.backgroundColor = [UIColor clearColor];
    [cell setSelectedBackgroundView:backView];

    // set highlight text color to dark gray
    float colValue = 0.2;
    [cell.textLabel setHighlightedTextColor:[UIColor colorWithRed:colValue green:colValue blue:colValue alpha:1]];

    // set title
    [cell.textLabel setText:[(self.subjects)[indexPath.row] caption]];

    return cell;
}

这与应用程序中的所有其他表格完全相同,但在此特定表格中,一个单元格始终为白色,如下面的屏幕截图所示。

这发生在我的 iPhone 4S 以及模拟器中。 我试图从手机/模拟器中删除应用程序,重新启动 XCode,清理并重建解决方案,没有任何改变。

【问题讨论】:

  • Xcode 调试器在那个实例中告诉你什么?
  • 对我来说一切都很正常。右键单击并“打印描述...”将其写入日志:<UITableViewCell: 0x10c5c060; frame = (0 0; 320 44); text = 'Air Law'; hidden = YES; autoresize = W; autoresizesSubviews = NO; layer = <CALayer: 0x10c30ea0>> 在变量视图中展开变量时,我得到以下信息:screenshot

标签: ios uitableview


【解决方案1】:

我不确定这是如何或为什么会这样,但问题与setBackgroundColor: 方法有关。如果我完全删除它,问题仍然存在,但是将其设置为除[UIColor clearColor] 之外的任何颜色不会更改背景颜色,但单元格显示正确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多