由于iOS 7,视图不会显示 [英] View does not appear because of iOS 7

查看:110
本文介绍了由于iOS 7,视图不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 7的iPhone上尝试了我的应用程序,除了一件事,一切都很完美。在iOS 6版本上,当我执行以下代码时,加载视图(带有activityindicator)出现并在加载结束时消失。在iOS 7上,视图在加载过程中根本不显示。

I tried my app on my iPhone with iOS 7 and everything works perfectly except one thing. On iOS 6 versions, when I executed the following code, the loading view (with the activityindicator) appeared and disappeared at the end of the loading. On iOS 7, the view does not appear at all during the loading.

self.loadingView.alpha = 1.0;
[self performSelector:@selector(accessServices) withObject:nil afterDelay:0.0f];

AccessServices方法:

AccessServices method :

- (void)accessServices {
     // Getting JSON stuff
     // The code is OK, I just don't copy/paste it here

     self.loadingView.alpha = 0.0;
}

会发生什么?这是iOS 7的错误吗?

What happens ? Is it an iOS 7 bug ?

推荐答案

我不希望上述代码的行为发生变化,尽管我毫不奇怪它可能不会像你期望的那样工作。如果您在主队列上执行JSON操作,则代码将依赖于UI更新发生时的特性,而不是使其显式化。

I wouldn't have expected the behavior of the above code to change, though I'm not surprised that it might not work the way you expect. If you do the JSON stuff on the main queue, your code will be dependent on idiosyncrasies of when the UI update takes place, rather than making it explicit.

您可能希望将JSON代码显式地分派到后台队列,然后将最终的UI更新分发回主队列。这样的标准模式是:

You probably want to explicitly dispatch the JSON code to a background queue, and then dispatch the final UI update back to the main queue. The standard pattern for something like this is:

self.loadingView.alpha = 1.0;

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    // Getting JSON stuff
    // The code is OK, I just don't copy/paste it here

    dispatch_async(dispatch_get_main_queue(), ^{
        self.loadingView.alpha = 0.0;
    });
});

您可以使用GCD(如上所述)或操作队列等等。但是这个想法是相同的,UI更新应该发生在主队列上,但是任何远程计算成本高或者速度慢的东西都应该在后台队列上发生。

You can use GCD (like above) or operation queues, or whatever. But the idea is the same, that UI updates should happen on the main queue but that anything remotely computationally expensive or slow else should happen on a background queue.

这个模式应该无论iOS版本如何工作。

This pattern should work regardless of iOS version.

这篇关于由于iOS 7,视图不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆