2014-07-08 54 views
0

我可以手動在我的uitableviewcells上添加一個'行分隔符'(現成的iOS不會爲此剪切它)。所以我創建UIViews數組,稱爲_separatorLines,我從各指數的uitableviewcells'內容查看我‘的cellForRowAtIndexPath’加一的UIView與爲什麼我不能在啓動後更改UITableViewCell的ContentView

UIView *v   = [_separatorLines objectAtIndex:indexPath.row]; 
    [cell.contentView addSubview:v]; 

然而,當我選擇一個單元格,我想所有其他細胞'行分隔符變成紅色。 在「didSelectRowAtIndexPath方法」我有:

{ 
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]; 

相反,我沒有看到uitableviewcells改變的內容查看。

回答

0

對我來說,我認爲問題是行 NSIndexPath * I = [NSIndexPath indexPathForRow:i inSection:1];

UITableView從部分'0'開始(就像行開始於'0'一樣)。

而且還因爲我的UITableView是代表,我停止使用

[self tableView:tableView cellForRowAtIndexPath:I]; 

[self cellForRowAtIndexPath:I]; 

不知道取代它如果有什麼關係呢

相關問題