UItableView设置背景色ClearColor无效的问题

来源:互联网 发布:吾生有涯而知无涯解析 编辑:程序博客网 时间:2024/04/29 17:08

下班了写~

解决了之后找到了这个文章。他写的差不多了。

http://blog.csdn.net/xiaobo16/article/details/8102790


还原一下问题的场景!

本来是一个iphone的app。支持的好好的。

然后增加了ipad版本。

在login的页面,有个username和password的tableview。

在iphone 4s iphone 5,ipad 3(都已经升到了6.0 及以上)等设备上都是没有问题的。

设置tableView背景色也没通过代码,只是 IB里面设置一下background color 为 clear color:PS:很久以前的工程,当时还没脱离IB。

然后突然来个一台ipad2 ,版本是5.0.1.然后就尴尬了。

login的页面tableView的背景色说什么都不能换。---前提:我的tableVIew是grouped,不是plain的。

然后我就先试了两个color,发现不是这问题。然后我就试着设置一下backgroundView。----发现就好了。。


然后网上随便搜搜原因,就找到上面哪个blog 也说遇到了类似的情况,好像和我情况是不太一样。我在ios6以后的都是好的。莫名其妙在ipad的5.0.1版本上除了这个问题。解决嘛:就是这样的了。tableView.backgroundView = nil;tableView.backgroundColor = [UIColor clearColor];

The backgroundColor property is a property inherited from UIView, setting it to be clearColor allows the window/view behind the table view to show through. This works fine on the iPhone but will no longer work on the iPadbecause the backgroundView is in the way.

顺着连接我又看到了入戏的评论,

That seemed to work.  I just did:

 

    UIView *theView = [[UIView allocinitWithFrame:self.testTableView.frame];

    [theView setBackgroundColor:[UIColor clearColor]];

    [self.testTableView setBackgroundView:theView];

 

background is now clear.  Still seems like a bug though.  I feel like [tableView setBackgroundColor:[UIColor clearColor]]; should work.



It's not a bug, UITableView's grouped style has a view behind it to allow for more advanced things, like images. backgroundColor only works in plain-style table views.

 

Or at least that's how I understand it.

 

Erway Software


原创粉丝点击