为什么可以';更改UITableViewCell';启动后的内容视图

为什么可以';更改UITableViewCell';启动后的内容视图,uitableview,setcontentview,Uitableview,Setcontentview,我可以在uitableviewcells上方手动添加一个“行分隔符”(开箱即用的iOS并没有为此进行剪切)。因此,我创建了一个UIView数组,称为_separatorLines,我使用 UIView *v = [_separatorLines objectAtIndex:indexPath.row]; [cell.contentView addSubview:v]; 但是,当我选择一个单元格时,我希望所有其他单元格的行分隔符都变为红色。 在“DidSelectRowa

我可以在uitableviewcells上方手动添加一个“行分隔符”(开箱即用的iOS并没有为此进行剪切)。因此,我创建了一个UIView数组,称为_separatorLines,我使用

  UIView *v         = [_separatorLines objectAtIndex:indexPath.row];
  [cell.contentView addSubview:v];
但是,当我选择一个单元格时,我希望所有其他单元格的行分隔符都变为红色。 在“DidSelectRowatineXpath”中,我有:

{
for(unsigned int i = 0; i < _rowsInSection-1; i ++)
{
  //make all other rows have a red content view
  if(i != indexPath.row)
  {
            NSIndexPath *I = [NSIndexPath indexPathForRow:i inSection:1];
            UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:I];

            UIView *separatingLineView = [_separatorLines objectAtIndex:I.row+1];
            separatingLineView.backgroundColor = [UIColor redColor];
            [cell.contentView bringSubviewToFront:separatingLineView];
            [separatingLineView setNeedsDisplay];

            [cell setNeedsDisplay];
            [cell.contentView setNeedsDisplay];
        }
    }

  [self setNeedsDisplay];
{
for(无符号整数i=0;i<\u行第1节;i++)
{
//使所有其他行具有红色内容视图
if(i!=indexPath.row)
{
nsindepath*I=[nsindepath indexPathForRow:I第1节];
UITableViewCell*cell=[self tableView:tableView cellForRowAtIndexPath:I];
UIView*separatingLineView=[\u separatorLines对象索引:I.row+1];
separatingLineView.backgroundColor=[UIColor redColor];
[cell.contentView将子视图带到前面:分隔线视图];
[separatingLineView设置需要显示];
[单元格设置需要显示];
[cell.contentView setNeedsDisplay];
}
}
[自我设置需要显示];

相反,我没有看到uitableviewcells的contentView发生变化。

对我来说,我认为问题在于行 nsindepath*I=[nsindepath indexPathForRow:I第1节]

UITableView从节“0”开始(就像行从“0”开始一样)

另外,由于我的UITableView是委托,我停止使用

[self tableView:tableView cellForRowAtIndexPath:I];
并将其替换为

[self cellForRowAtIndexPath:I];
不确定这是否与此有关