0

I have setup a UITableView as follows:

// Create sub view for fields
fieldView = [[UITableView alloc] initWithFrame:CGRectMake(0, logoView.bounds.size.height, 320, 160) style:UITableViewStyleGrouped];
fieldView.delegate = self;
fieldView.dataSource = self;
fieldView.scrollEnabled = NO;
[fieldView setBackgroundColor:[UIColor whiteColor]];
fieldView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin;

Pretty simple view here, I put two fields into the cells. Before anyone asks... I am using a table view out of personal choice and best appearance.

The issue I have is that I want to use the

style:UITableViewStyleGrouped

because I feel it looks the best layout. The issue is that if I setBackground as a color on the table view in ios6 it is not updated. In ios5 simulator I see the change, not in ios6. What I am looking for is the grouped style within the tableview but have control over the background color for that section of the view. Does this mean by only option would be to use a view for the tableview instead and if so does anyone know how to easily replicate the tableview style in a view programatically

4

3 回答 3

2

The UITableViewStyleGrouped makes use of backgroundView. So if you don't want the default background set it to nil:

fieldView.backgroundView = nil;

Then it will use the backgroundColor you set.

于 2013-02-22T19:06:36.490 回答
0

I have not tried this with a grouped style in particular, so this is just something to try: Instead of calling setBackgroundColor, what happens if you set the table view's backgroundView? You could set it to any UIView whose background color you have previously set.

于 2013-02-22T19:06:24.353 回答
-1

Use -tableView:willDisplayCell:forRowAtIndexPath: to intercept the cell and color as needed.

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row % 3)
        cell.backgroundColor = [UIColor redColor];
}

This works with grouped tableviews, in storyboards, whatever.

于 2013-02-22T19:11:37.073 回答