我想在加载 tableView 之前有一个“正在加载” View Controller 。您能否推荐执行此操作的最佳方法,并在可能的情况下提供一些代码。
理想情况下,加载屏幕将有一个事件指示和一个显示正在加载的标签。
在 UITableView 之上添加一个 UIView。
最佳答案
首先在你的.h中定义这些
@property (strong, nonatomic) UIView *loadingView;
然后在您的 viewWillAppear
中,在开始加载 TableView 数据之前,创建并显示 View :
if(!_loadingView)
{
_loadingView = [[UIView alloc] initWithFrame:self.view.frame];
[loadingView setBackgroundColor:[UIColor lightGrayColor]];
UIActivityIndicatorView *actInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[actInd setFrame:CGRectMake((loadingView.frame.size.width / 2 - 10), (loadingView.frame.size.height / 2 - 10), 20, 20)];
UILabel *lblLoading = [[UILabel alloc] initWithFrame:CGRectMake((_loadingView.frame.size.width / 2 - 30), (_loadingView.frame.size.height / 2 - 5), 60, 30)];
lblLoading.text = @"Loading";
// you will probably need to adjust those frame values to get it centered
[loadingView addSubview:actInd];
[loadingView addSubview:lblLoading];
[actInd startAnimating];
}
[_yourTableView addSubview:_loadingView];
然后当您完成加载数据时:
[_loadingView removeFromSuperView];
如果您使用 Storyboard...只需将 UIView
拖到您的 UIViewController
上,确保它位于 UITableView
之上(它不会需要是 UITableView
的 subview )。将 UIActivityIndicatorView
和 UILabel
拖到上面,然后为 UIView
创建一个导出。
然后在你的viewWillAppear
[_loadingView setHidden NO];
然后当你完成加载
[_loadingView setHidden YES];
关于ios - 如何在 tableView 之前添加 "Loading" View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19708371/