setNetworkActivityIndi​​catorVisible 微调器不显示

发布于 2024-11-13 18:42:58 字数 948 浏览 7 评论 0原文

正如标题所示,这里有一些代码:

- (void)refreshMap {
    NSLog(@"refreshing");
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    lat = [[NSNumber numberWithDouble:myUserLocation.coordinate.latitude] stringValue];
    lon = [[NSNumber numberWithDouble:myUserLocation.coordinate.longitude] stringValue];

    NSString *url = [[NSString alloc] initWithFormat:@"http://mywebsite.com/geo_search.json?lat=%@&lon=%@", lat, lon];
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:60.0];
    [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    [url release];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}

网络活动指示器(在状态栏中)根本不出现(不在模拟器中,也不在真实设备上)。 我该如何解决这个问题?

As the title says, here's some code:

- (void)refreshMap {
    NSLog(@"refreshing");
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    lat = [[NSNumber numberWithDouble:myUserLocation.coordinate.latitude] stringValue];
    lon = [[NSNumber numberWithDouble:myUserLocation.coordinate.longitude] stringValue];

    NSString *url = [[NSString alloc] initWithFormat:@"http://mywebsite.com/geo_search.json?lat=%@&lon=%@", lat, lon];
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:60.0];
    [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    [url release];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}

The network activity indicator (in the status bar) doesn't appear at all (not in the Simulator, nor on a real device).
How do I solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪装你 2024-11-20 18:42:58

除非您的代码将控制权返回给运行循环,否则 UI 不会更新。因此,如果您以相同的方法启用和禁用网络指示器,它实际上永远不会显示。解决方案是调用

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

url 连接委托方法(conectionDidFinishLoading:connection:didFailWithError:)。

The UI won't be updated unless your code returns control to the runloop. So if you enable and disable the network indicator in the same method, it will never actually show. The solution is to call

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

in your url connection delegate methods (conectionDidFinishLoading: and connection:didFailWithError:).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文