2012-05-07 75 views
0

我有一個表視圖,而且我動態重裝它的內容,重新加載表的內容,我用下面的代碼:UITableView的reloadData不設置單元格顯示屬性正確

[agendaTable reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade]; 

這工作得很好,但問題是我設置表格單元格的alpha屬性以下列方式:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 


    if([cell isKindOfClass:[AgendaItemBlank class]]) 
     cell.backgroundColor = [UIColor clearColor]; 

    else if([cell isKindOfClass:[AgendaItem class]]) 
    { 
     cell.backgroundColor = [UIColor whiteColor]; 

     [cell setAlpha:0.82]; 

     //set the corner radius so that there is a rounded effect 
     [cell.layer setBorderWidth:0.5]; 
     [cell.layer setCornerRadius:9.0]; 
     [cell.layer setBorderColor:[UIColor redColor].CGColor]; 
     [cell.layer setMasksToBounds:YES]; 

     //set a different color for the selected background 
     UIView *bgColorView = [[UIView alloc] init]; 
     [bgColorView setBackgroundColor:[UIColor redColor]]; 
     [bgColorView.layer setCornerRadius:9.0]; 
     [cell setSelectedBackgroundView:bgColorView]; 
     [bgColorView release]; 
    } 
} 

的是,重裝後,表格單元格開始變得不透明的這些鉛的事實相結合,所有的屬性取效果但不是alpha屬性。

細胞在上下滾動時(基本上是重繪時)會重新獲得其alpha屬性。

我也嘗試在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath內設置alpha,但這沒有任何作用。

+0

是否已確認willDisplayCell獲取調用?或者它被調用的順序。我的猜測是,它正在調用,但在淡出的動畫邏輯發生之前,該邏輯再次改變alpha。在這種情況下,您可能必須將您的動畫選擇更改爲不影響Alpha的動畫。 –

+0

是的,它確實被調用。但是我不確定哪個動畫可以防止影響alpha。我試過UITableViewRowAnimationNone,即使這影響了alpha。 – Jyotirmoy

回答

0

嘗試

[cell setBackgroundColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:0.82]]; 
[cell.textLabel setBackgroundColor:[UIColor clearColor]]; 
+0

謝謝,它有幫助。它驚人的看到這個工作,而[單元格setAlpha:]在重新加載期間失敗。 – Jyotirmoy

0

要設置單元格背景使用中間UIView對象:

UIView* cellBackView = [[UIView alloc] initWithFrame:CGRectZero]; 
cellBackView.backgroundColor = [UIColor redColor]; 
cellBackView.alpha = 0.82; 
cell.backgroundView = cellBackView; 
相關問題