我很难从 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 添加到当前视图上方的超级视图.当我尝试这个时,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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!