如何在当前UITableViewController上添加UIView [英] How to add a UIView above the current UITableViewController

查看:747
本文介绍了如何在当前UITableViewController上添加UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难在UITableViewController的viewDidLoad方法中添加子视图(UIView)

I have difficulty adding a subview (UIView) from within the viewDidLoad method of a UITableViewController

这可行:

[self.view addSubview:self.progView];

但你可以通过UIView progView看到表格单元格出血。

But you can see the table cell lines bleed through the UIView progView.

我尝试过这种方法:

[self.view.superview insertSubview:self.progView aboveSubview:self.view];

这是尝试将progView,UIView添加到当前视图上方的superview。当我尝试这个时,UIView永远不会出现。

Which is an attempt to add the progView, UIView to the superview, above the current view. When I try this, the UIView never appears.

- 更新 -

以下是最新的尝试:

UIView *myProgView = (UIView *)self.progView; //progView is a method that returns a UIView

[self.tableView insertSubview:myProgView aboveSubview:self.tableView]; 
[self.tableView bringSubviewToFront:myProgView];

结果与[self.view addSubview:self.progView]相同; UIView出现但似乎在桌子后面。

Result is the same as [self.view addSubview:self.progView]; The UIView appears but seemingly behind the Table.

推荐答案

我尝试了上面的方法,但没有让它发挥作用。我还发现它需要太多的配置和代码,因为它需要从头开始设置表视图(这可以在故事板中轻松完成)。

I tried the approach above, but did not get it to work. I also found it to require too much configuration and code, since it requires setting up the table view from scratch (something that is easily done from within the storyboard).

,我添加了一个视图,我想将我的UITableView添加到UITableViewController的UINavigationController视图中,如下所示:

Instead, I added the view that I wanted to add above my UITableView into the UITableViewController's UINavigationController's view, as such:

[self.navigationController.view addSubview:<view to add above the table view>];

这种方法要求你在UINavigationController中嵌入UITableViewController,但即使你不想要导航控制器,你仍然可以使用这种方法,只需隐藏导航栏。

This approach requires that you have embedded the UITableViewController in a UINavigationController, but even if you do not want a navigation controller, you can still use this approach and just hide the navigation bar.

这篇关于如何在当前UITableViewController上添加UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆