UITableView的背景颜色不变 [英] UITableView background color does not change

查看:134
本文介绍了UITableView的背景颜色不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在模型UIViewController中我有以下loadView的实现(一切都是以编程方式创建的):

In a model UIViewController I have the following implementation of loadView (everything is created programmatically):

- (void)loadView {

    // Add Basic View
    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 540, 620)];
    myView.backgroundColor = [UIColor clearColor];
    self.view = myView;
    [myView release];

    // Add NavigationBar

    // Add a BG image

    // Add Table
    UITableView *tbView = [[UITableView alloc] initWithFrame:CGRectMake(30, 80, 480, 250) style:UITableViewStyleGrouped];
    tbView.dataSource = self;
    tbView.delegate = self;
    tbView.scrollEnabled = NO;
    tbView.backgroundColor = [UIColor clearColor];
    [tbView reloadData];

    [self.view addSubview:tbView];
    [tbView release];

    // some more code
}

看到我设置backgroundColor到clearColor,但当我编译和运行代码我总是看到一个灰色的背景后面的表:

As you can see I set backgroundColor to clearColor, yet when I compile and run the code I always see a gray background behind the table:

我不明白我做错了什么(听起来很蠢,我知道),我曾经有过相同的代码和它工作完全正常。我正在使用iOS SDK 4.2.1编译

I don't understand what I am doing wrong (sounds stupid, I know), I used to have the very same code and it worked perfectly fine. I am compiling with iOS SDK 4.2.1

推荐答案

您还需要将UITableView的backgroundView属性设置为nil )版本的iOS。

You also need to set your UITableView's backgroundView property to nil on recent (since 3.2) versions of iOS.

因此,添加...

tbView.backgroundView = nil;

...应该排序您的问题。

...should sort your problems.

也就是说,如果你想保持与3.2之前的设备的兼容性,你应该在调用它之前通过 instancesRespondToSelector 方法检查是否存在这个。

That said, if you want to maintain compatibilty with pre-3.2 devices, you should check for the existence of this via the instancesRespondToSelector method before calling it.

这篇关于UITableView的背景颜色不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆