2010-03-01 74 views
1

自定義TableviewCell如何根據部分自定義UITableViewCell的背景圖像?例如。在第一節中,單元格應該有一個綠色的.png圖像作爲背景圖像,而在第二節中,單元格應該有一個紅色的.png圖像作爲背景。根據部分

回答

2

有關如何訪問和使用節信息,請參閱Populating the Table View With Data

當您有多個部分時,您將實施一些可選的表格視圖源方法來處理部分。

然後,當你創建細胞,檢查它是哪一部分,並設置它因此,在:

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

在這種方法中,你可以訪問indexPath.section和格式化你的細胞。

請參閱Table View Programming Guide for more

UIKit adds property sectionNSIndexPath因此,您可以從傳入上述方法的索引路徑獲取section(請參閱鏈接的第一個示例)。

0

例如:

if(section == 0) { 
background.image = [UIImage imageNamed:@"green.png"]; 


} 
else if(section == 1) { 

background.image = [UIImage imageNamed:@"blue.png"]; 

}