2011-12-15 247 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行),然后构建项目。

你瞧:该表是现在正确显示。我讨厌在开发工具上花费几天的时间来解决一些愚蠢的错误。