2009-12-07 39 views
3

我遇到了阻擋背景圖片的UITableViewCell內部的標籤問題。看起來好像它只發生在未選擇的狀態。我試圖設置背景顏色清除,但沒有做到這一點。它採用tableview的背景色。我是否也必須設置標籤背景圖片?UITableViewCell中的標籤阻擋背景

// Neither of these worked... 
cell.textLabel.backgroundColor = [UIColor clearColor]; 
cell.contentView.backgroundColor = [UIColor clearColor]; 

screen shot

這裏是我的cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableIdentifier"]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"SimpleTableIdentifier"] autorelease]; 
    } 

    UIImage *image = [UIImage imageNamed:@"TableRow.png"]; 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
    imageView.contentMode = UIViewContentModeScaleToFill; 
    cell.backgroundView = imageView; 
    [imageView release]; 

    UIImage *imageSelected = [UIImage imageNamed:@"TableRowSelected.png"]; 
    UIImageView *imageViewSelected = [[UIImageView alloc] initWithImage:imageSelected]; 
    imageViewSelected.contentMode = UIViewContentModeScaleToFill; 
    cell.selectedBackgroundView = imageViewSelected; 
    [imageViewSelected release]; 


    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    cell.textLabel.textColor = [UIColor whiteColor]; 
    cell.textLabel.text = [[self.trivia.questionsets objectAtIndex:indexPath.row] valueForKeyPath:@"title"]; 

    return cell; 
} 

UPDATE:還挺解決...

如果我設置表格的背景顏色(我假定會在一切之下)清除,然後突然間我的圖像顯示出我期望的位置,但是桌子後面地面現在顯示了一切的頂部?這是預期的行爲? (還沒有檢查該文檔在此還)

tableView.backgroundColor = [UIColor redColor]; 
cell.contentView.backgroundColor = [UIColor orangeColor]; 
cell.textLabel.backgroundColor = [UIColor yellowColor]; 

screen shot 2

...並完成,如果我設置表和單元格背景顏色以清除,我們是很好的。文本標籤背景顏色沒有區別。

tableView.backgroundColor = [UIColor clearColor]; 
cell.contentView.backgroundColor = [UIColor clearColor]; 
cell.textLabel.backgroundColor = [UIColor yellowColor]; 

screen shot 3

+0

你使用的是什麼base sdk?以及如何設置您的手機的文本 – 2009-12-08 07:08:12

+0

SDK 3.1.2,我粘貼我的完整cellForRowAtIndexPath在上述問題 – rob5408 2009-12-08 07:45:08

+1

@Spooky,感謝您修復圖像! – rob5408 2015-06-22 02:15:33

回答

0

啊這是預期的行爲。

你的tableview是一個子視圖,坐在一切的前面。如果有什麼東西在桌面前(即背景),它會掩蓋桌子。