2011-01-22 51 views
0

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

(它是制作渐变背景)

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

EDIT(黑场被添加,因为该应用程序还没有完成。):

我可以添加在这个方法工作的UITableViewCell上,我做了我自己的子类,但我在哪里使用UITableViewDefaultStyle它不起作用。

+1

任何静态属性初始化像accessoryType和backgroundView你可以移动if(cell == nill){...} – Victor 2011-01-22 22:01:04

回答

6

的好地方设置clearColor是

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

我想你应该设置为clearColor也内容查看。

+0

谢谢!虽然它可以在模拟器和更高版本的iOS上运行,但它的确有窍门。移动for-loop就足够了。 – LuckyLuke 2011-01-22 22:44:12