Victor Engel
Victor Engel

Reputation: 2133

Table view not appearing the same way in iOS7 as it did in iOS6

The relevant part of the code is in - tableView:cellForRowAtIndexPath::

cell.textLabel.backgroundColor = [UIColor clearColor];
if (indexPath.row == 0) {
   cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",result.level]]];
} else {
   cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",indexPath.row+OFFSETTOFIRSTROW]]];
}
cell.backgroundView.alpha = 0.5;
cell.backgroundColor = [UIColor darkGrayColor];
if (totalPieces) {
   cell.textLabel.textColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.1 alpha:1.0];
   cell.textLabel.shadowColor = [UIColor blackColor];
   if (indexPath.row == 0) {
      cell.textLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.5 blue:0.0 alpha:1.0];
      cell.textLabel.textColor = [UIColor yellowColor];
      cell.backgroundView.alpha = 1.0;
   }
   cell.textLabel.shadowOffset = CGSizeMake(1.0, 1.0);
} else {
   cell.textLabel.textColor = [UIColor blackColor];
   cell.textLabel.shadowColor = nil;
}

Essentially, each row of the table has its own background image. This appears correctly in iOS6. But in iOS7, what happens is that the image is covered by what appears to be the background color. That is, until the user scrolls the table. When the user scrolls the table, it displays properly. What's making it behave differently upon first presentation? What should I do to fix it?

The intended result is a background color of dark grey covering the whole cell. Above that is the background image, which has some transparency, through which the background color should show. Above that is the text, which has a transparent background so the image/cell background shows through.

Unless I hear something else, I suppose what I'll do is to stack two images instead of using the cell background.

Upvotes: 0

Views: 445

Answers (3)

Amitabha
Amitabha

Reputation: 1662

First clear the background view of cell by setting it to nil. Then set a custom view

[cell setBackgroundView: nil];
UIView* bview = [[UIView alloc] init];
bview.backgroundColor = [UIColor colorWithPatternImage:@"your image"];
[cell setBackgroundView:bview];

This worked for me.. Hope it will work for you too.. :-) Best of luck..

Upvotes: 1

Victor Engel
Victor Engel

Reputation: 2133

OK. This solution works, although maybe there's a more efficient one.

cell.textLabel.backgroundColor = [UIColor clearColor];
UIView *backgroundView = [[UIView alloc] initWithFrame:cell.bounds];
backgroundView.backgroundColor = [UIColor darkGrayColor];
if (indexPath.row == 0) {
   [backgroundView addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",result.level]]]];
   cell.backgroundView = backgroundView;
} else {
   [backgroundView addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",indexPath.row+OFFSETTOFIRSTROW]]]];
   cell.backgroundView = backgroundView;
}

Upvotes: 0

Enrico Susatyo
Enrico Susatyo

Reputation: 19800

This is an intended change by Apple. To fix it change cell.backgroundColor to [UIColor clearColor].

Upvotes: 0

Related Questions