开发者

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];

f开发者_如何学Cor (UIView *view in cell.contentView.subviews) {
    view.backgroundColor = [UIColor clearColor];
}

return cell;    
}

Problems with background on UITableViewCell iPhone

(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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜