在 tableview 上添加视图(UITableViewController) [英] Add view over tableview (UITableViewController)
问题描述
情况: 我有一个 UITableViewController 从服务异步加载一些数据.在此期间,我想在显示我的自定义指示器和文本的表格视图上放置一个全屏(导航栏除外)视图.
Situation: I've got a UITableViewController loading some data asynchronously from a service. During this time I would like to place a full screen (except navigation bar) view over the table view showing my custom indicator and text.
问题:我面临的问题是,当我的自定义视图(它有红色背景)放置在 UITableView 上时,表格视图的线条通过我的自定义视图显示(请参阅下图).
Problem: The problem I'm facing is that when my custom view (it has a red background) is placed over the UITableView the lines of the table view are shown trough my custom view (see image below).
我的尝试:我尝试使用 insertBelow 和更高版本,没有用.我也尝试这样做:tableview.Hidden = true,但这也出于某种原因隐藏了自定义视图,如图 2 所示.
What I tried: I tried to use insertBelow and above, didn't work. I also tried to do: tableview.Hidden = true, but this also hides the custom view for some reason as seen on image 2.
Image1:出于某种原因,我可以看到线条抛出了我的观点.
Image1: For some reason I can see the lines threw my view.
图片 2:当使用 hidden = true 时,Tableview + 自定义视图消失了.
Image 2: Tableview + custom view gone when hidden = true used.
我的代码:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
UIView view = new UIView (new RectangleF (0, 0, this.TableView.Frame.Width, this.TableView.Frame.Height));
view.BackgroundColor = UIColor.Red;
this.TableView.AddSubview (view);
TableView.Source = new SessionTableViewSource ();
}
推荐答案
问题是 UITableViewController
的 View 是一个 UITableView
,所以你不能添加子视图到桌子顶部的控制器.
The issue is that the View of a UITableViewController
is a UITableView
, so you cannot add subviews to the controller on top of the table.
我建议从 UITableViewController
切换到包含 UITableView
的简单 UIViewController
.这样,控制器主视图是一个包含表格的普通 UIView
,您可以向主 UIView
添加子视图,它们将被放置在表格视图的顶部.
I'd recommend switching from a UITableViewController
to a simple UIViewController
that contains a UITableView
. This way the controller main view is a plain UIView
that contains a table, and you can add subviews to the main UIView
and they will be placed on top of the table view.
这篇关于在 tableview 上添加视图(UITableViewController)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!