2

タイトルが示すように、ここにいくつかのコードがあります:

- (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];
}

ネットワークアクティビティインジケーター(ステータスバー内)はまったく表示されません(シミュレーターにも実際のデバイスにも表示されません)。どうすればこれを解決できますか?

4

1 に答える 1

7

コードが制御をrunloopに戻さない限り、UIは更新されません。したがって、同じ方法でネットワークインジケーターを有効または無効にした場合、実際に表示されることはありません。解決策は

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

URL接続デリゲートメソッド(conectionDidFinishLoading:およびconnection:didFailWithError:)。

于 2011-06-05T21:48:35.370 に答える