我尝试使用以下代码在此 MapView 中的 NavigationBar 上显示 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] );
}
}];
}
}