2010-08-02 96 views
3

嘿大家,这似乎应该是一个简单的;我真的很希望它是。一如既往,先谢谢!iPhone:分组TableView背景图像问题

我想要做的是将一个背景图像添加到分组样式tableview。我使用在viewDidLoad中下面的方法:

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; 

不幸的是,background.png似乎如下要绘制不仅是细胞的背后,却也对细胞的背景和标题:

alt text http://www.freeimagehosting.net/uploads/194449ffc1.png

我知道在这个网站上有几个问题可以解决类似的问题,但是我担心我什么都得不到。 How can I set the background of UITableView (the tableview style is "Grouped") to use an image?导致我

self.tableView.opaque = NO; 
self.tableView.backgroundView = nil; 

增加viewDidLoad中,并在配置我的单元格添加

cell.backgroundView = nil; 
cell.opaque = NO; 

。不用说,它不起作用。添加

cell.backgroundColor = [UIColor clearColor]; 

也没有工作。可悲的是,那是我最后的想法。如果可能的话,我真的很希望能够在不添加界面构建器中的背景的情况下做到这一点。我宁愿尽可能多地编程。我希望问这不是太贪心。再次感谢!

* * * 编辑: * * *

我碰到另一种方法来实现这一点,但遇到了另一个问题。我下面的代码添加到viewDidLoad中:

UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
    [self.tableView.window addSubview:bgView]; 

    [self.tableView addSubview:bgView]; 
    [self.tableView sendSubviewToBack:bgView]; 

它看起来有前途的,它可能是,但不幸的是在给我的以下内容: alt text http://www.freeimagehosting.net/uploads/c02dd68e20.png

看起来好像它要么是没有被发送到后面和标题以某种方式显示出来,或者细胞跟着它回来。我一点也不确定。任何建议在这里也将不胜感激。

这里就是我发现的编辑代码: Add UIView behind UITableView in UITableViewController code

回答

0

我还没有想通了,为什么上面不工作或如何让这样做,而是通过增加子视图进行修改在App Delegate中的窗口而不是tableView在这里,我能够得到它的工作。

而不是只是让它的功能和继续我想实际学习,所以我仍然好奇我的错在上面。因此,我会暂时搁置一段时间,如果你能告诉我我的错误,我会给你最后的投票和绿色的复选标记。谢谢!

4

我经历了类似的道路,你在这里描述的东西。我终于发现,我在工作后的以下答案:

How to set the background of a UITableView to an image?

这是张贴由用户RKB两行代码。下面的代码:

self.tableView.backgroundColor = [UIColor clearColor]; 

self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithData:imageData]]; 
2

使用以往的回应(尤其是来自dana_a)这是我开始工作同样的事情

self.tableView.backgroundColor =的UIColor clearColor] self.parentViewController.view.backgroundcolor = [UIColor colorWithPatternImage:[UIImge imageNamed:@“bgtest2.png”]];

这是在我的viewWillAppear:方法在我的情况下具有分组tableview的详细视图控制器。

1

我把这段代码放在我的ViewDidLoad方法中,它工作得很漂亮。

self.termsTableView.backgroundColor = [UIColor clearColor]; 

self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"metal4.png"]]; 
3

另一个解决方案,如果没有别的在这里工作。在viewDidLoad中:

UIImage *background = [UIImage imageNamed:@"MyBackground.png"]; 
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:background]; 

这将会把你静态的(不伸展或移动)的后面所有的分组的tableview元素,如标题和细胞背景。