简体   繁体   English

构建表时如何在UITableViewController中显示视图?

[英]How can I display a view within a UITableViewController while it's building the table?

I'd like to add a progress bar to this view and display a blank table while it's loading in data. 我想在此视图中添加进度条,并在加载数据时显示空白表。 Any idea how I do this? 知道我该怎么做吗?

Currently I've tried adding this view as a subview in viewDidLoad and viewWillAppear but both show a black screen until the table is built. 目前,我已尝试将此视图作为子视图添加到viewDidLoad和viewWillAppear中,但是在构建表之前,它们都显示黑屏。

Thanks! 谢谢!

You can use ATMHud for the progress bar and do a row insert on your table once you are done preloading data. 您可以将ATMHud用于进度栏,并在完成预加载数据后在表上插入一行 Add this anywhere in your view controller: 将此添加到视图控制器中的任何位置:

ATMHud *myHud = [[[ATMHud alloc] initWithDelegate:self] autorelease];
[myHud setCaption:@"loading stuff"];
[self addSubview:myHud.view];
[myHud show];
// ... load data ....
[myHud hide];

In the view controller that controls your tableview int he view did load method add a the cover view with loading info as a subview to the tableview. 在控制您的TableView的视图控制器中,View View加载方法将带有Load Info的Cover View作为子视图添加到TableView。 When the data is ready or your tableview finishes loading add a method to remove this loading view. 当数据准备好或您的tableview完成加载时,添加一种方法来删除此加载视图。

- (void)viewDidLoad
{
   [tableview addSubview:mycoverView]; 
}  

- (void)removeCoverView
{
   [mycoverView removeFromSuperView];
}

!Make sure that you set the bounds to resize the view so that its size will cover the table view. !请确保设置边界以调整视图的大小,以便其大小能覆盖表格视图。 If you if you don't resize it you may never see it. 如果您不调整大小,则可能永远看不到它。 You may want to change the background color to something obvious (red) so that you see where the view actually is when its added to the tableview for troubleshooting. 您可能需要将背景颜色更改为明显的颜色(红色),以便在将视图添加到表视图中以进行故障排除时查看视图的实际位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM