【发布时间】:2011-09-19 17:02:40
【问题描述】:
我确信这是一个已经被问及并得到解答的问题,但我似乎找不到我需要的东西。我正在尝试自定义 UITableView 的背景,为此,我创建了 UITableViewCell 的子类,并使用 IB 构建了自定义单元格。我成功地将自定义单元格连接到表格视图,所以我得到的单元格正在显示。我正在尝试更改每个单元格的背景,所以这是我使用的:
if(row == 1){
rowBackground = [UIImage imageNamed:@"VehicleExpenses_button.png"];
selectionBackground = [UIImage imageNamed:@"VehicleExpenses_button_selected.png"];
((UIImageView *)cell.backgroundView).image = rowBackground;
// ((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;
}
内
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
我的 Controller 类的方法。我检查了调试器,代码中的所有行都被调用了......
有什么想法吗?
这是整个方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"HomeViewCell";
static NSString *CellNib = @"HomeViewCell";
UIImage *rowBackground;
UIImage *selectionBackground;
NSInteger row = [indexPath row];
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
cell = (UITableViewCell *)[nib objectAtIndex:0];
}
if(row == 1){
rowBackground = [UIImage imageNamed:@"VehicleExpenses_button.png"];
selectionBackground = [UIImage imageNamed:@"VehicleExpenses_button_selected.png"];
((UIImageView *)cell.backgroundView).image = rowBackground;
// ((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;
}
// perform additional custom work...
return cell;
}
【问题讨论】:
标签: iphone uitableview xcode4