setNetworkActivityIndicatorVisible 微调器不显示
正如标题所示,这里有一些代码:
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您的代码将控制权返回给运行循环,否则 UI 不会更新。因此,如果您以相同的方法启用和禁用网络指示器,它实际上永远不会显示。解决方案是调用
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
in your url connection delegate methods (
conectionDidFinishLoading:
andconnection:didFailWithError:
).