2010-09-05 33 views
3

,我嘗試設置當前選中的單元格的背景。我知道在Three20樣式表的概念,但它只是提供:如何在three20的TTTableViewController中獲取用戶定義的背景顏色具有TTTableViewController實例的TTTableViewController

- (UITableViewCellSelectionStyle)tableSelectionStyle { 
    return UITableViewCellSelectionStyleGray; 
} 

與標準選項UITableViewCellSelectionStyleNone,UITableViewCellSelectionStyleBlue,UITableViewCellSelectionStyleGray。

其次,我知道,UITableView實現只需要一個子類UITableViewCell。人們會設置電池類的selectedBackgroundView:

UIView *myBackView = [[UIView alloc] initWithFrame:self.frame]; 
myBackView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0.75 alpha:1]; 
self.selectedBackgroundView = myBackView; 
[myBackView release]; 

如何設置一個選擇的電池在three20的TTTableViewController實例的背景顏色?

回答

1

今晚我明白了這一點。我進入了320UI.xcodeproj並查看了UITableViewCell的構建位置,即數據源,然後我將該數據源分類爲我用來設置我的表的那個數據源。

例如,如果你目前正使用一個TTSectionedDataSource表,那麼你繼承,讓我們說,我們把它叫做MySectionedDataSource,然後該子類實現內部,你會想要做這樣的事情:

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

      UIView *view = [[UIView alloc] initWithFrame: CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.width, cell.height)]; 
       view.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0.75 alpha:1]; 
       cell.selectedBackgroundView = view; 
    } 

這應該做到這一點。

起初,我試圖設置的

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

內selectedBackgroundView,但似乎並沒有工作。我搜索了代碼以找出原因,即如果控制器,代理,單元或數據源中的某些內容正在重新設置bg選擇,但沒有任何內容。我結束了必須在技術上搜索,我沒有自己解決它... :)

祝你好運。

相關問題