UITableViewCell iPhone背景问题

Luc*_*uke 0 iphone

我班上的代码如下.当我在模拟器上启动我的应用程序时,它可以工作.但是,当在实际设备(iPhone 1g,3.1.3)上启动应用程序时,它不起作用.有任何想法吗?

(这是为了制作渐变背景)

- (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;    
}
Run Code Online (Sandbox Code Playgroud)

温度

(添加了黑色字段,因为应用尚未完成.)

编辑:

我可以在UITableViewCell上添加这个方法,我已经创建了自己的子类,但是我使用的是UITableViewDefaultStyle它不起作用.

Vic*_*tor 6

设置clearColor的好地方是

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { ... }
Run Code Online (Sandbox Code Playgroud)

我认为你也应该为contentView设置clearColor.