在MapView加载后从XML加载注释

时间:2013-03-05 06:15:04

标签: iphone objective-c xcode4.5

有没有办法首先加载MapView然后用注释填充它?

我之所以提出这样的原因:当我点击我首先调用我的XML填充注释的地图时,会出现延迟,然后只有我的MapView打开视图。

我担心的是,如果XML增长,它会进一步延迟或超时。

1 个答案:

答案 0 :(得分:0)

请参阅此代码:

#import "MapViewController.h"
#import "MapViewAnnotation.h"

@implementation MapViewController

@synthesize mapView;

// When the view loads
- (void)viewDidLoad
{

    [self performSelector:@selector(addAnnotation) withObject:@"" afterDelay:5.0];
}

//here i am delaying my annotation to 5 second so my map can first display

-(void)addAnnotation
{
    // Set some coordinates for our position (Buckingham Palace!)
    CLLocationCoordinate2D location;
    location.latitude = (double) 51.501468;
    location.longitude = (double) -0.141596;

    // Add the annotation to our map view
    MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Buckingham Palace" andCoordinate:location];
    [self.mapView addAnnotation:newAnnotation];
    [newAnnotation release];
}

// When a map annotation point is added, zoom to it (1500 range)
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *annotationView = [views objectAtIndex:0];
    id <MKAnnotation> mp = [annotationView annotation];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);
    [mv setRegion:region animated:YES];
    [mv selectAnnotation:mp animated:YES];
}

// Received memory warning
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

// If the view unloads, release the map view
- (void)viewDidUnload {
    [super viewDidUnload];
    [mapView release];
    mapView = nil;
}

// Deallocations
- (void)dealloc {
    [mapView release];
    [super dealloc];
}

@end