2011-12-15 238 views
0

我有我的行項目的UITableView圖像暗背景被初始化爲默認的UITableViewCell(所有者文件是委託並表的數據源):在默認情況下的UITableViewCell

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; 
    switch (indexPath.row) { 
     case 0: 
      cell.imageView.image = [UIImage imageNamed:@"icon_facebook.png"]; 
      cell.textLabel.text = kShareFacebook; 
      break; 
     case 1: 
      cell.imageView.image = [UIImage imageNamed:@"icon_twitter.png"]; 
      cell.textLabel.text = kShareTwitter; 
      break; 
     case 2: 
      cell.imageView.image = [UIImage imageNamed:@"icon_clipboard.png"]; 
      cell.textLabel.text = kShareClipboard; 
      break; 
     default: 
      break; 

    } 

    return cell; 
} 

這一切工作正常然而當顯示錶,圖像被顯示在較暗的背景和有沿着行的右邊緣較暗的餘量,如可在此圖像中可以看出: screenshot 我試圖使用以清除該背景一些/所有的組合:

[cell setBackgroundColor:[UIColor whiteColor]]; 
[cell.imageView setBackgroundColor:[UIColor whiteColor]]; 
[cell setIndentationLevel:1]; 
[cell setOpaque:YES]; 

但是這沒有幫助。我如何擺脫黑暗的背景,讓整個細胞出現在白色背景上?

+0

您是否使用IB來設置UITableView? – Mutix 2011-12-15 10:30:27

回答

0

這肯定是iOS之一,或者很可能是XCode的流氓之一。我刪除了IB中的表並刪除了我的.m文件中的相應代碼。然後我保存並關閉了該項目並退出XCode。

打開Xcode和項目後,我再次打開在IB的視圖控制器並重新添加表,並重新建立所有代表。我添加了代碼來將整個表格的背景設置爲透明(這不能通過IB來完成,因此我將該代碼放在viewDidLoad方法中)。然後我重寫了cellForRowAtIndexPath方法(沒有複製粘貼,只是重新輸入 - 沒有問題,反正只有10行),然後構建項目。

你瞧:該表是現在正確顯示。我討厭在開發工具上花費幾天的時間來解決一些愚蠢的錯誤。