iOS4网络ActivityIndicatorVisible通过UI被阻止
我正在请求下载一些图像,然后我想用它们替换子视图。 这意味着 UI 被阻止,稍后会显示新视图。
我希望用户明白,阻塞是由于下载而发生的。
首先,我尝试使用
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[self downloadFunction];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
That 导致活动指示器最大程度地闪烁(几乎没有),因为我的请求阻塞了 UI 线程。
我无法将 downloadFunction 置于后台,因为我依赖于在推送控制器之前可用的下载数据(会导致错误“不支持多次推送相同的视图控制器实例”,因为我可以单击按钮不止一次)。
然后我尝试在视图顶部放置一个带有旋转轮的子视图:
[self performSelectorInBackground:@selector(showActivitySubView) withObject:nil];
or
[NSThread detachNewThreadSelector: @selector(showActivitySubView) toTarget:self withObject:nil];
但 UI 仍然被阻止,并且我的指示器在下载完成后才显示...
有什么想法吗?
I am doing a request to download some images then I want to replace the subview with them.
This means that the UI is blocked and then the new view displays sometime later.
I want the user to understand that the blocking occurs due to the download.
First I tried to use
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[self downloadFunction];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
That leads to maxium a blink (mostly nothing) of the Activity Indicator, since my request is blocking the UI thread.
I cannot put the downloadFunction to the background, since I depend on the downloaded data to be available before i push the controller (would lead to the Error "Pushing the same view controller instance more than once is not supported" since I could click the button more than once).
Then I tried to put a subview with a spinning wheel on top of the view:
[self performSelectorInBackground:@selector(showActivitySubView) withObject:nil];
or
[NSThread detachNewThreadSelector: @selector(showActivitySubView) toTarget:self withObject:nil];
but still the UI is blocked and my indicator is just displayed after the download finished...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以简单地将方法分成两部分,并使用定时调用来允许 UI 刷新线程在阻塞主线程之前启动。例如:
可能有更好的方法来做到这一点,我不确定任务栏上的小指示器是否足以让应用程序审查人员满意的活动指示,但这应该可行并且不需要线程。
You can simply split your method in two and use a timed call to allow the UI refresh thread to pick up before you block the main thread. For example:
There's probably a better way of doing this, and I'm not sure that the little indicator on the task bar would be enough activity indication to keep the app review folks happy, but this should work and won't require threading.