2011-05-19 77 views
1

我想默認我的表格視圖中的頂部單元格,只要子視圖出現就會突出顯示。目標C:如何在視圖加載時突出顯示錶視圖中的第一個單元格?

我試着這樣做:

switch(indexPath.row) { // assuming there is only one section 
    case 0: 
     cell.textLabel.text = @"First Cell:"; 
     cell.highlighted = YES 
     break; 

但是,當我得到一個黑色覆蓋在我的第一個單元格,而不是這不起作用。

編輯(添加截圖)

enter image description here

在這個任何建議將不勝感激!

感謝

回答

3

我想你需要的是,

cell.selected = YES; 

如果你想它的動畫,你可以使用,

[cell setSelected:YES animated:YES]; 
+0

感謝您的回覆。是的,我也嘗試過,結果相同。我在原始文章中附加了截圖 – Zhen 2011-05-19 04:09:28

+0

@ Zhen:您爲cell.textLabel設置了任何bg顏色? – EmptyStack 2011-05-19 04:15:46

+0

nope,我所做的只是設置textColor。一切都按默認 – Zhen 2011-05-19 04:19:28

4

我有完全相同的問題。您需要將代碼移到willDisplayCell中,而不是cellForRowAtIndexPath。

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

    if(indexPath.row == 0) { 

     [cell setSelected:YES animated:NO]; 
    } 
} 
相關問題