iphone SDK:如何将图像子视图添加到 UITableViewController 并仍然看到单元格?
我正在将图像子视图添加到带有分组表的 UITableViewController 中。添加图像子视图后,我可以看到图像顶部的表格标题,但单元格被绘制在图像后面。
我还需要做些什么来确保表格单元格出现在背景图像的顶部吗?这是我在 UITableViewControlle 的 viewDidLoad 中使用的代码:
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 959.0f);
UIImageView *backImageView = [[UIImageView alloc] initWithFrame:myImageRect];
[backImageView setImage:[UIImage imageNamed:@"somebackground.png"]];
[self.view addSubview:backImageView];
[self.view sendSubviewToBack:backImageView];
[backImageView release];
我意识到作为替代方案,我可以简单地创建一个复合视图并将表视图放在它上面,而不是我在这里尝试做的事情。如果没有任何其他解决方案,我会这样做,但如果可能的话,我更愿意使用我正在尝试的方法。
I'm adding an image subview to an UITableViewController with a grouped table. Once I add the image subview I can see the table headers on top of the image, but the cells are being drawn behind the image.
Is there something else I need to do to ensure that the table cells appear on top of the background image? Here is the code I'm using in the UITableViewControlle's viewDidLoad:
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 959.0f);
UIImageView *backImageView = [[UIImageView alloc] initWithFrame:myImageRect];
[backImageView setImage:[UIImage imageNamed:@"somebackground.png"]];
[self.view addSubview:backImageView];
[self.view sendSubviewToBack:backImageView];
[backImageView release];
I realize that as an alternative I could simply create a composite view and drop the tableview on top of it rather than what I am trying to do here. If there isn't any other solution I will do so, but would prefer to use the approach I'm trying if at all possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个分组表视图。来自苹果文档:
这意味着在您的表格后面插入了一个默认的图像视图。您想用您自己的视图替换它,如下所示:
这将用您自己的视图替换其他背景视图。否则,当再次布局表格视图时,其他背景图像将覆盖您的背景图像。
It's a grouped table view. From the apple docs:
This means that there is an default image view being inserted behind your table. You want to replace that with your own view, like so:
This replaces the other backgroundView with your own. Otherwise when the table view is laid out again, that other background image will overlay yours.
看来 UITableView 在刷新时经常会重新排列视图的 zorder。因此,您需要手动管理在任何表事件(例如插入/删除/更新行)上重置 zorder。
It appears that the UITableView will often rearrange the zorder of views when refreshing. So, you need to manually manage resetting the zorder on any table events such as inserting/deleting/updating rows.