子视图出现在表视图后面
当我向 UITableViewController 添加子视图时,它似乎位于表视图下方。我可能错误地加载了子视图,或者在错误的位置调用了 addSubview
。我指的子视图是选项卡栏上方的红色区域,其中还包含“Click me”按钮:
您可以看到细胞系有重叠。这是我在 TableViewController 中添加子视图的位置:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect hRect = CGRectMake(0, 170, 320, 480);
HomeScreenOverlayView *homeView = [[HomeScreenOverlayView alloc] initWithFrame:hRect];
[self.tableView addSubview:homeView];
[homeView release];
}
有什么想法吗?谢谢!
When I add a subview to my UITableViewController, it seems to be underneath the tableview. I may be loading my subview incorrectly, or calling addSubview
in the wrong place. The subview I'm referring to is the red area above the tabbar that also contains the "Click me" button:
You can see that the cell lines kind of overlap. Here is where I'm adding the subview in my TableViewController:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect hRect = CGRectMake(0, 170, 320, 480);
HomeScreenOverlayView *homeView = [[HomeScreenOverlayView alloc] initWithFrame:hRect];
[self.tableView addSubview:homeView];
[homeView release];
}
Any ideas? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我自己也遇到过这个问题,并通过不向表添加视图,而是将视图添加到表的超级视图来解决它。
当您想要屏蔽整个表格(例如加载屏幕)时,这特别有用。
注意,我通常会将其添加到视图生命周期中的 viewWillAppear: 中。
I have had this issue myself and resolved it by not adding a view to the table, but rather adding the view to the table's superview.
This is particularly useful when you want to mask the entire table (e.g. loading screens).
N.B. I will usually add this to viewWillAppear: in the view's lifecycle.
当您调用 addSubview 时,它可能是添加到表视图中的第一个视图。稍后,所有单元格和支持视图都将添加到您的视图上。
最好的办法是创建一个空视图,并向其中添加表视图和覆盖视图,确保覆盖视图位于表视图上方。
视图具有绘图、交互和布局三个作用。拥有一个只扮演其中一个角色的视图是很好的。
When you call addSubview, it is probably the first view added to the table view. Later, all the cells and support views will be added over your view.
The best thing to do is create an empty view and add both the table view and overlay view to it, making sure the overlay view is above the table view.
Views serve the 3 roles of drawing, interaction and layout. It is fine to have a view that only fills one of those roles.
您可以使用
- (void)sendSubviewToBack:(UIView *)view
或- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index
。addSubview
始终将新视图放在前面。编辑:抱歉,误读了问题,看起来您希望子视图位于前面。
You can use
- (void)sendSubviewToBack:(UIView *)view
or- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index
.addSubview
always puts the new view in front.EDIT: Sorry, misread the question, it looks like you want the subview to be in front.