Je l'ai fait bouillir un ensemble très complexe de services Web et des recherches jusqu'au simple code suivant. Je dois être en mesure d'ajouter des annotations à une carte en réponse à une recherche (ou dans l'échantillon ci-dessous pour le clic d'un bouton), puis permettre à l'utilisateur de cliquer sur le bouton à nouveau et obtenir une nouvelle série de résultats. En réalité, il y aura un nombre différent, mais dans l'exemple simplifié, nous ajoutons toujours une annotation à l'MapView. Je crois que mon code devrait supprimer les annotations existantes et ajouter une nouvelle, mais il fuit 32 octets bouton deuxième pousse et les suivantes. Qu'est-ce que je rate ? (Ou retenir que le cas!)
testViewController.h
#import <UIKit / UIKit.h>
#import <MapKit / MapKit.h>
#import MyMark.h
@interface testViewController: UIViewController {
MKMapView * Mapview;
}
@fin
testViewController.m
- (id) initWithNibName: (NSString *) paquet nibNameOrNil: (NSBundle *) {nibBundleOrNil
si (self = [super initWithNibName: bundle nibNameOrNil: nibBundleOrNil]) {
// initialisation personnalisée
self.title = @ test;
}
retour auto;
}
- (void) storeLocationInfo: (CLLocationCoordinate2D) Titre loc: (NSString *) t sous-titre: (NSString *) st index: (int) i {
NSArray * annotations = [Mapview annotations];
[Mapview RemoveAnnotations: annotations];
MyMark * mymark = [[MyMark alloc] initWithCoordinate: loc];
[Mapview AddAnnotation: mymark];
[Libération MyMark];
}
- (void) {viewDidLoad
[Super viewDidLoad];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithTitle: @ style Ajouter un point à la carte: cible UIBarButtonItemStylePlain: auto l'action: @selector (addPushed)];
[Self.navigationItem setRightBarButtonItem: barButton];
[Libération 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];
[Libération MapView];
}
- (void) {addPushed
MKCoordinateRegion reg = mapView.region;
[Auto storeLocationInfo: titre reg.center: @ prix sous-titre: @ title index: 1];
}
- (void) {dealloc
[Super dealloc];
}
MyMark.h
#import <Foundation / Foundation.h>
#import <MapKit / MapKit.h>
@interface MyMark: NSObject <MKAnnotation> {
CLLocationCoordinate2D coordonnées;
NSString titre *;
NSString * sous-titre;
index int;
}
@property (non atomique, en lecture seule) CLLocationCoordinate2D de coordonnées;
@property (non atomique, en lecture seule) int index;
@property (nonatomic, conserver) NSString titre *;
@property (nonatomic, conserver) NSString * sous-titre;
- (id) initWithCoordinate: (CLLocationCoordinate2D) de coordonnées;
- (id) setCoordinate: (CLLocationCoordinate2D) de coordonnées;
- (id) setString: (NSString *) t sous-titre: index (NSString *) st: (int) i;
@fin
MyMark.m
#import MyMark.h
@implementation MyMark
@synthesize de coordonnées, l'indice;
titre @synthesize, sous-titre;
- (id) initWithCoordinate: (CLLocationCoordinate2D) c {
coordonner = c;
NSLog (@ % f,% f, c.latitude, c.longitude);
retour auto;
}
- (id) setCoordinate: (CLLocationCoordinate2D) c {
coordonner = c;
NSLog (@ % f,% f, c.latitude, c.longitude);
retour auto;
}
- (id) setString: (NSString *) t sous-titre: index (NSString *) st: (int) i {
self.title = t;
self.subtitle = st;
= indice i;
retour auto;
}
- (void) {dealloc
[Communiqué de titre];
[Libération des sous-titres];
[Super dealloc];
}













