默认UITableViewCell中的图像上的黑暗背景

时间:2011-12-15 10:12:35

标签: iphone uitableview background

我的项目中有一个UITableView,行被初始化为默认的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 我试图使用some / all的组合来清除背景:

[cell setBackgroundColor:[UIColor whiteColor]];
[cell.imageView setBackgroundColor:[UIColor whiteColor]];
[cell setIndentationLevel:1];
[cell setOpaque:YES];
然而,这并没有帮助。如何摆脱黑暗的背景,使整个细胞出现在白色背景上?

1 个答案:

答案 0 :(得分:0)

这一定是iOS之一,或者很可能是XCode的侥幸。我删除了IB中的表并删除了.m文件中的相应代码。然后我保存并关闭了项目并退出XCode。

打开XCode和项目后,我再次打开IB中的ViewController并再次添加表,并再次设置所有委托。我添加了代码以将整个表的背景设置为透明(这不能通过IB完成,因此我将该代码放在viewDidLoad方法中)。然后我重写了cellForRowAtIndexPath方法(没有复制粘贴,只是重新输入它 - 没问题,反正只有大约10行)并构建项目。

瞧瞧:桌子现在正确显示了。我讨厌在开发工具中花一些时间来处理一些愚蠢的错误。