How to add a UIView above the current UITableViewController(如何在当前 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 添加到当前视图上方的超级视图.当我尝试这个时,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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在当前 UITableViewController 上方添加一个 UIView


基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01