正如标题所说,这是一些代码:
- (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];
}
网络活动指示器(状态栏中)根本不显示(不在模拟器中,也不在真实设备上)。 我该如何解决这个问题?
答案 0 :(得分:7)
除非您的代码将控制权返回给runloop,否则不会更新UI。因此,如果您以相同的方法启用和禁用网络指示器,它将永远不会显示。解决方案是致电
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
在您的网址连接委托方法(conectionDidFinishLoading:
和connection:didFailWithError:
)。