2009-09-10 56 views
5

我試圖給tableviewcell的不同backgroundColor s與colorwithPatternImage並且它不按預期方式工作。該文件沒有提到一次只能使用一種模式。UIColor colorWithPatternImage只使用一個圖像

說我有3行,我設置背景像這樣:

Cell1.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"red.png"]]; 

Cell2.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"green.png"]]; 

Cell3.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"blue.png"]]; 

所有3行會是紅色的。就好像有一些全球顏色正在返回。

colorWithPatternImage返回kCGColorSpaceModelPattern 1對於每次調用,無論傳入什麼圖像。如果確實一次只有一個全局模式,那麼顏色應該是最後一個設置,換句話說是藍色。

這沒有任何意義。有沒有人有任何內部專業知識蘋果在這裏做什麼?

編輯 我甚至在完全獨立的視圖中使用不同的模式,它仍然會影響其他視圖的模式。我相信,儘管文檔沒有說明這一點,但您一次只能使用一種UIColor圖像模式。傷心。

回答

1

據我可以看到這是不是或不再是真實的。我在這裏有幾個UITableViewCells,每個都有不同的backgroundImage,沒有任何問題。

+0

感謝您的更新:) – Brenden 2011-12-21 03:38:52

5

Cell1是什麼?你在哪裏設置這些?

我要說的是,你應該做這一切

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

    static NSString *CellIdentifier = @"Cell"; 

    MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) {  
     // create cell 
    } 

    // Set up the cell... 

    // set up a background color 
    if (something) 
     cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"red.png"]]; 
    else (another) 
     cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"green.png"]]; 
    else 
     cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"blue.png"]]; 
} 
+0

我正在這樣做。因此,一個單元格被返回,所以表格可以顯示它。單元格[1-3]實際上在switch中都是一個case語句, – Brenden 2009-09-11 22:07:53

相關問題