如何在iPhone中的表格视图单元格中设置背景图像

Pug*_*gal 2 iphone cocoa-touch background-image uitableview

我想为单元格设置背景图像.我已经在表格视图中为单元格设置了背景图像.但是我想在表格视图单元格中为背景图像设置两个图像.我想为背景设置备用单元格,

喜欢,

  Image1- Cell 1, Cell 3, Cell 5, Etc.,

  Imgae-2- Cell 2, Cell 4,Cell 6, Etc.,
Run Code Online (Sandbox Code Playgroud)

请指导我并给我一些示例链接.

谢谢!

epa*_*tel 8

您可以为下面的偶数/不均匀行设置两个不同的单元格

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    static NSString *CellIdentifierEvenRows = @"MyCellEven";
    static NSString *CellIdentifierUnevenRows = @"MyCellUneven";
    UITableViewCell *cell;

    if (indexPath.row % 2) {
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierUnevenRows];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                           reuseIdentifier:CellIdentifierUnevenRows] autorelease];
            cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"uneven.png"] autorelease];
        }
    } else {
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierEvenRows];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                           reuseIdentifier:CellIdentifierEvenRows] autorelease];
            cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"even.png"] autorelease];
        }
    }

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

(虽未测试)