在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:当隐藏=真实使用时,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 ();
}
推荐答案
问题在于View一个 UITableViewController
是一个 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
切换到简单的 UIViewController
包含 UITableView
。这样控制器主视图是一个包含表的普通 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屋!