LuckyLuke
LuckyLuke

Reputation: 49077

Problems with background on UITableViewCell iPhone

I the following code in my class. When I launch my app on the simulator it works. However when launcing the app on an actual device(iPhone 1g, 3.1.3) it does not work. Any ideas?

(it's for making gradient background)

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MainScreenCellID];

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

cell.textLabel.text = [[[self.controllers objectAtIndex:[indexPath row]] navigationItem] title];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

UIImageView *bgimage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell_bg.png"]];
cell.backgroundView = bgimage;
[bgimage release];

for (UIView *view in cell.contentView.subviews) {
    view.backgroundColor = [UIColor clearColor];
}

return cell;    
}

temp

(Black fields is added because the app is not done yet.)

EDIT:

I can add that on the UITableViewCell which this method work on I have made my own subclasses, but where I am using the UITableViewDefaultStyle it does not work.

Upvotes: 0

Views: 220

Answers (1)

Victor
Victor

Reputation: 3517

The good place for setting clearColor is

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { ... }

I think you should set clearColor for contentView also.

Upvotes: 6

Related Questions