我想在我的iPhone程序中的简单分组表视图中使用固定的图像作为背景。不幸的是,无论我做什么,背景总是纯白色的。我已经按照本站和其他站点上的一些所谓的解决方案进行了尝试,但都没有成功。以下是表格视图控制器类的viewDidLoad方法中相关的代码(注意,为了简单起见,此代码使用了纯蓝色而不是图像):
self.tableView.opaque = NO;
self.tableView.backgroundColor = [UIColor clearColor];
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
backgroundView.backgroundColor = [UIColor blueColor];
[self.tableView.window addSubview:backgroundView];
[backgroundView release];
我怀疑我的backgroundView视图的位置不正确。我尝试过sendToBack:,bringToFront:和其他方法,但总是只得到一个白色背景。在UITableViewController中是否可以这样做?我必须使用Interface Builder吗?
subviews
属性返回一个NSArray
,该对象不响应-addSubview:
方法。 - Alex ReynoldsUIView
的addSubview
方法即可。 - Adam Woś