【问题标题】:Why UITableViewCell highlighted color in edit mode is not shown为什么 UITableViewCell 在编辑模式下突出显示颜色未显示
【发布时间】:2013-04-17 17:29:51
【问题描述】:

我有一个 UITableView,当它处于编辑模式时,所选单元格的背景突出显示,但我分配给单元格标签的突出显示颜色没有在编辑模式下应用,尽管它在选择时工作正常普通模式。

UILabel *desc = [[[UILabel alloc]initWithFrame:CGRectMake(self.textXStart, descYStart, self.descWidth, descHeight)]autorelease];
desc.lineBreakMode = self.descLineBreakMode;
desc.font = font;
desc.textAlignment = NSTextAlignmentLeft;
desc.numberOfLines = self.descLinesNumber;
desc.text = descText;

desc.highlightedTextColor = [UIColor whiteColor];

然后我将它添加到单元格内容视图中

在普通情况下,突出显示的颜色会显示,但是当我单击编辑按钮并选择一个单元格时,标签文本没有突出显示的颜色。

你认为这个问题的原因是什么。

【问题讨论】:

  • 可以多发一些周边的代码吗?我只是尝试将该代码粘贴到一个项目中(删除位以设置字体、对齐方式、行数),它似乎可以 100% 正常工作。我的表格设置为允许在编辑期间进行单选。尝试构建一个仅具有最小行为的新项目(具有单个表的单个视图,以及添加带有 hilightedTextColor 的标签的代码),看看您是否可以复制该行为。

标签: ios objective-c uitableview


【解决方案1】:

如果您已将allowsMultipleSelectionDuringEditing 设置为YES,则UITableView“进入编辑模式时不查询编辑样式”,如类参考中所述:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableView/allowsMultipleSelectionDuringEditing

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。对我有用的是覆盖 didSelectRowAtIndexPath 和 didDeselectRowAtIndexPath 并在我的自定义单元格中手动设置标签的颜色。

    您还需要确保在进入和退出编辑模式时调用重新加载数据。

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated
    {
        [super setEditing:editing animated:animated];
        [[self tableView] reloadData];
    }
    
    - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
        DocumentCell *cell = (DocumentCell *) [tableView cellForRowAtIndexPath:indexPath];
        if([cell isEditing]) {
            cell.titleLabel.textColor = [UIColor blackColor];
            cell.dateLabel.textColor = [UIColor blackColor];
            cell.tagsLabel.textColor = [UIColor blackColor];
        }
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        DocumentCell *cell = (DocumentCell *) [tableView cellForRowAtIndexPath:indexPath];
        if([cell isEditing]) {
            cell.titleLabel.textColor = [UIColor whiteColor];
            cell.dateLabel.textColor = [UIColor whiteColor];
            cell.tagsLabel.textColor = [UIColor whiteColor];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-02
      • 1970-01-01
      • 2011-04-14
      • 2020-11-13
      相关资源
      最近更新 更多