Setting UITableViewCell

I am trying to tune UITableViewCell to a "pretty" application and I am having problems. My code is:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIImage *rowBackground;
UIImage *selectionBackground;
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
NSInteger row = [indexPath row];

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if ( cell == nil ) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

if (row == 0 && row == sectionRows - 1) {
    rowBackground = [UIImage imageNamed:@"topAndBottomRow.png"];
    selectionBackground = [UIImage imageNamed:@"topAndBottomRowSelected.png"];
    NSLog(@"topAndBottom");
}
else if ( row == 0 ) {
    rowBackground = [UIImage imageNamed:@"topRow.png"];
    selectionBackground = [UIImage imageNamed:@"topRowSelected.png"];
    NSLog(@"topRow");
}
else if ( row == sectionRows - 1 ) {
    rowBackground = [UIImage imageNamed:@"bottomRow.png"];
    selectionBackground = [UIImage imageNamed:@"bottomRowSelected.png"];
    NSLog(@"bottomRow");
} else {
    rowBackground = [UIImage imageNamed:@"middleRow.png"];
    selectionBackground = [UIImage imageNamed:@"middleRowSelected.png"];
    NSLog(@"middleRow");
}

((UIImageView *)cell.backgroundView).image = rowBackground;
((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;

NSString *cellValue = [[listOfItems objectAtIndex:indexPath.row] description];
cell.textLabel.text = cellValue;

return cell;                 
}

It selects the appropriate image, as shown in the console log, but I have two problems: 1. Installation (cell.backgroundView) .image does not affect 2. Set errors (cell.selectedBackgroundView) .image: - [UITableViewCellSelectedBackground setImage:]: unrecognized selector sent to instance 0x4b90670

I can find hints about UIView's issues with this in google, but haven't found anything about UITableViewCell. Help?

+3
source share
1 answer

- , , IIRC, UIView. -, UIImageView, yourelf.

, backgroundView UIImageView * , :

cell.backgroundView = [[[UIImageView alloc] init] autorelease];

..., .

+4

All Articles