Iphone UITableView单元格背景,如';音乐';应用程序

Iphone UITableView单元格背景,如';音乐';应用程序,iphone,objective-c,ios,xcode,uitableview,Iphone,Objective C,Ios,Xcode,Uitableview,可能重复: 我想要一个背景正常的单元格,下一个背景不错的单元格,如下图所示: 对于如何在无限数量的单元中实现这个漂亮且干净的方法,有什么想法吗? 提前谢谢 嘶嘶作响: -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableVi

可能重复:

我想要一个背景正常的单元格,下一个背景不错的单元格,如下图所示: 对于如何在无限数量的单元中实现这个漂亮且干净的方法,有什么想法吗? 提前谢谢

嘶嘶作响:

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

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

    if ((indexPath.row % 2) == 0) {
        [cell.contentView setBackgroundColor:[UIColor whiteColor]];
        [cell.textLabel setBackgroundColor:[UIColor whiteColor]];
    }
    else {
        [cell.contentView setBackgroundColor:[UIColor colorWithRed:243.0f/255.0f green:243.0f/255.0f blue:243.0f/255.0f alpha:1.0f]];
        [cell.textLabel setBackgroundColor:[UIColor colorWithRed:243.0f/255.0f green:243.0f/255.0f blue:243.0f/255.0f alpha:1.0f]];
    }
    cell.textLabel.text = [songArray objectAtIndex:indexPath.row];
    return cell;
}
嘶嘶作响:

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

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

    if ((indexPath.row % 2) == 0) {
        [cell.contentView setBackgroundColor:[UIColor whiteColor]];
        [cell.textLabel setBackgroundColor:[UIColor whiteColor]];
    }
    else {
        [cell.contentView setBackgroundColor:[UIColor colorWithRed:243.0f/255.0f green:243.0f/255.0f blue:243.0f/255.0f alpha:1.0f]];
        [cell.textLabel setBackgroundColor:[UIColor colorWithRed:243.0f/255.0f green:243.0f/255.0f blue:243.0f/255.0f alpha:1.0f]];
    }
    cell.textLabel.text = [songArray objectAtIndex:indexPath.row];
    return cell;
}

这是一个“很棒”的背景…你尝试过什么?这些怎么样:第二个问题几乎就是你的问题。事实上,这基本上是一个重复。这是一个“伟大”的背景…你尝试了什么?这些怎么样:第二个问题几乎就是你的问题。事实上,这基本上是重复的。这种方法很好,除非你的单元格中有任何编辑附件。我尝试过的代码
[cell.accessoryView setBackgroundColor:[UIColor-color-withred:243.0f/255.0f-green:243.0f/255.0f-blue:243.0f/255.0f-alpha:1.0f]不起作用除非单元格中有任何编辑附件,否则这种方法可以。我尝试过的代码
[cell.accessoryView setBackgroundColor:[UIColor-color-withred:243.0f/255.0f-green:243.0f/255.0f-blue:243.0f/255.0f-alpha:1.0f]不起作用