在iPhone中的UITabBar一样应用活动的指标(Activity indicator in a

2019-09-18 06:07发布

我中的UITabBar一样+ UINavigationController的应用程序,它经常从互联网上需要的数据。 有时需要相当长的一段它得到它之前,我想展现一个活动的指标。

我试图为一个activityView在我的applicationDidFinishLaunching方法添加到我的窗口:

[window addSubview:tabBarController.view];
fullscreenLoadingView.hidden = YES;
[window addSubview:fullscreenLoadingView];

然后,我添加的应用程序委托作为观察员默认的通知中心:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startFullscreenLoading:) name:@"startFullscreenLoading" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopFullscreenLoading:) name:@"stopFullscreenLoading" object:nil];

并实现方法:

- (void)startFullscreenLoading:(NSNotification *)notification {
    fullscreenLoadingView.hidden = NO;
}

- (void)stopFullscreenLoading:(NSNotification *)notification {
    fullscreenLoadingView.hidden = YES;
}

当我然后在的applicationDidFinishLaunching方法使用该直接的装载指示器视图显示UPP如预期:

[[NSNotificationCenter defaultCenter] postNotificationName:@"startFullscreenLoading" object:self];

但是,当我使用它的导航控制器之一的startFullscreenLoading:方法被调用,但我没有看到负载指示图。 这是为什么?

Answer 1:

你加载在后台线程你的数据? 你的主线程将被阻塞,及将无法重绘或处理任何其他事件。



Answer 2:

我可以猜测最有可能的是,你的指标视图低于其他一些看法。 尝试

[[fullScreenLoadingView superView] bringSubviewToFront:fullScreenLoadingView]

如果不行,我会建议的内部瓦解-startFullscreenLoading以确保fullscreenLoadingView仍然有效。



Answer 3:

在我的应用我通过增加IB的UIActivityView,并确保它是高于一切(作为顶层对象)这样做。 它的设置停止时是看不见的。

然后在我的代码使它看起来与[activityIndi​​cator startAnimating],使其与[activityIndi​​cator stopAnimating]消失;



文章来源: Activity indicator in a UITabBar application on the iPhone