Я уверен, что это вопрос, который задавали и отвечали, но я не могу найти то, что мне нужно.Я пытаюсь настроить фон моего 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;
}