在我的 UIViewController 的 loadView 方法中,我启动了一个 UIActivityIndicator。稍后在 loadView 中,我加载了一个复杂的 UIView,加载大约需要 2-3 秒。(UIScrollView 有很多更具体的图片)。我的问题是 UIActivityIndicator 微调器只有在我的其他图层也加载后才可见。(这对我当然没用)。处理此问题的正确方法是什么?
- (void)loadView {
CGRect fullScreenRect=[[UIScreen mainScreen] bounds];
UIView *contentView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 340, fullScreenRect.size.width)]autorelease];
self.view = contentView;
spinner = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
spinner.center = self.view.center;
[self.view addSubview:spinner];
[spinner startAnimating];
scrollView=[[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 340, fullScreenRect.size.width)]autorelease];
...setting up scrollView...
[self.view addSubview:scrollView];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[spinner removeFromSuperview];
}
我发现了一个有点相似的线程: UIActivityIndicatorView not shown until after loading done
但它建议在后台线程中加载东西,但据我所知,加载和显示 UIView 只能在主线程中进行。
我是初学者,如果我的问题根本上是错误的,我很抱歉。