He hervido un conjunto muy complejo de servicios web y busco el siguiente código simple. Necesito poder agregar anotaciones a un mapa en respuesta a una búsqueda (o en el ejemplo siguiente al hacer clic en un botón), luego permitir que el usuario haga clic en el botón nuevamente y obtener un nuevo conjunto de resultados. En realidad, habrá un número diferente, pero en el ejemplo simplificado, siempre agregamos una anotación a la vista del mapa. Creo que mi código debería eliminar las anotaciones existentes y agregar una nueva, pero filtra 32 bytes en el segundo botón y luego empuja el botón. Qué me estoy perdiendo ? (O conservando según sea el caso)
testViewController.h
#import <UIKit / UIKit.h>
#import <MapKit / MapKit.h>
#import MyMark.h
@interface testViewController: UIViewController {
MKMapView * mapView;
}
@fin
testViewController.m
- (id) initWithNibName: (NSString *) paquete nibNameOrNil: (NSBundle *) nibBundleOrNil {
if (self = [super initWithNibName: nibNameOrNil paquete: nibBundleOrNil]) {
// Inicialización personalizada
self.title = @ prueba;
}
volverse a sí mismo;
}
- (void) storeLocationInfo: (CLLocationCoordinate2D) loc title: (NSString *) t subtítulo: (NSString *) st index: (int) i {
Anotaciones de NSArray * = [anotaciones de MapView];
[mapView removeAnnotations: anotaciones];
MyMark * mymark = [[MyMark alloc] initWithCoordinate: loc];
[mapView addAnnotation: mymark];
[Lanzamiento de MyMark];
}
- (void) viewDidLoad {
[super viewDidLoad];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithTitle: @ Agregar punto al mapa estilo: UIBarButtonItemStylePlain objetivo: acción propia: @selector (addPushed)];
[self.navigationItem setRightBarButtonItem: barButton];
[lanzamiento de barButton];
mapView = [[MKMapView alloc] initWithFrame: CGRectMake (0.0,0.0, self.view.frame.size.width, self.view.frame.size.height)];
mapView.showsUserLocation = FALSE;
mapView.delegate = self;
[self.view insertSubview: mapView atIndex: 0];
[vista mapView];
}
- (void) addPushed {
MKCoordinateRegion reg = mapView.region;
[self storeLocationInfo: título de reg.center: @ subtítulo de precio: @ título índice: 1];
}
- (void) dealloc {
[super dealloc];
}
MyMark.h
#import <Fundación / Fundación.h>
#import <MapKit / MapKit.h>
@interface MyMark: NSObject <MKAnnotation> {
CLLocationCoordinate2D coordenada;
Título NSString *;
Subtítulo NSString *;
índice int;
}
@property (nonatomic, readonly) Coordinación CLLocationCoordinate2D;
@property (nonatomic, readonly) int index;
@property (nonatomic, retener) NSString * title;
@property (nonatomic, retain) Subtítulo NSString *;
- (id) initWithCoordinate: (CLLocationCoordinate2D) coordenada;
- (id) setCoordinate: (CLLocationCoordinate2D) coordenada;
- (id) setTitle: (NSString *) t subtítulo: (NSString *) st índice: (int) i;
@fin
MyMark.m
#import MyMark.h
@implementation MyMark
@synthesize coordinate, index;
@synthesize title, subtitle;
- (id) initWithCoordinate: (CLLocationCoordinate2D) c {
coordenadas = c;
NSLog (@ % f,% f, c.latitude, c.longitude);
volverse a sí mismo;
}
- (id) setCoordinate: (CLLocationCoordinate2D) c {
coordenadas = c;
NSLog (@ % f,% f, c.latitude, c.longitude);
volverse a sí mismo;
}
- (id) setTitle: (NSString *) t subtítulo: (NSString *) st index: (int) i {
self.title = t;
self.subtitle = st;
índice = i;
volverse a sí mismo;
}
- (void) dealloc {
[lanzamiento del título];
[lanzamiento de subtítulos];
[super dealloc];
}













