简体   繁体   English

UITableViewCell iPhone上的背景问题

[英]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. 但是,当在实际设备(iPhone 1g,3.1.3)上启动应用程序时,它不起作用。 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;    
}

温度

(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. 我可以在该方法起作用的UITableViewCell上添加我自己的子类,但是在使用UITableViewDefaultStyle的地方它不起作用。

The good place for setting clearColor is 设置clearColor的好地方是

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

I think you should set clearColor for contentView also. 我认为您也应该为contentView设置clearColor。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM