我試圖用以下代碼在此MapView中的NavigationBar上顯示UIActivityIndicator。但是,無論我嘗試哪種方式,我都無法顯示它。這裏有什麼竅門?另外,我正試圖從服務器獲取地圖註釋並在地圖上顯示背景,這是否是這樣做的?UIActivityIndicator不顯示在此代碼的導航欄中
- (void)viewDidLoad
{
[super viewDidLoad];
self.activityIndicatorView = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
self.activityIndicatorView.hidesWhenStopped = YES;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:self.activityIndicatorView];
[self.activityIndicatorView startAnimating];
[self performSelectorInBackground:@selector(loadMapAnnotations) withObject: nil];
[self.activityIndicatorView stopAnimating];
}
//=========================================================================
-(void)loadMapAnnotations
{
self.mapView.showsUserLocation = YES;
if(self.vManager = [VendorManager getVendorManager])
{
NSLog(@"VendorManager = %@",[self.vManager description]);
[self.vManager vendorsNearLocation:userLocation block:^(NSArray *vendors,
NSError *error)
{
if(vendors && [vendors count])
{
for (id v in vendors)
{
Vendor *aVendor = [[Vendor alloc] initWithAttributes:v];
NSLog(@"Vendor from Vendors = %@",[aVendor name]);
[self.mapView addAnnotation:aVendor];
}
}
else
{
NSLog(@"Failed to get vendors: %@", [error description]);
}
}];
}
}
不知道爲什麼有人低估了這一點。請至少留下評論,以便我瞭解爲什麼。 – banditKing