Ik heb een zeer complex geheel van webservices en zoekopdrachten neer op de eenvoudige onderstaande code. Ik moet in staat zijn om aantekeningen toe te voegen aan een kaart in reactie op een zoekopdracht (of in het onderstaande voorbeeld op de klik van een knop), dan kan de gebruiker nogmaals op de knop en krijgen een nieuwe set van de resultaten. In werkelijkheid zal er een ander aantal zijn, maar in de vereenvoudigde voorbeeld hebben we een annotatie toe te voegen altijd aan de MapView. Ik geloof dat mijn code moet de bestaande annotaties te verwijderen en een nieuwe toevoegen, maar het lekt 32 bytes op tweede en volgende knop duwt. Wat mis ik ? (Of behouden zoals het geval kan zijn!)
testViewController.h
#import <UIKit / UIKit.h>
#import <MapKit / MapKit.h>
#import MyMark.h
@interface testViewController: UIViewController {
MKMapView * mapView;
}
@einde
testViewController.m
- (id) initWithNibName: (NSString *) nibNameOrNil bundel: (NSBundle *) nibBundleOrNil {
if (zelf = [super initWithNibName: nibNameOrNil bundel: nibBundleOrNil]) {
// initialisatie Custom
self.title = @ test;
}
terugkeer zelf;
}
- (void) storeLocationInfo: (CLLocationCoordinate2D) loc titel: (NSString *) t ondertitel: (NSString *) st index: (int) i {
NSArray * annotaties = [mapView aantekeningen];
[MapView removeAnnotations: aantekeningen];
MyMark * mymark = [[MyMark VERD] initWithCoordinate: loc];
[MapView addAnnotation: mymark];
[MyMark vrijgave];
}
- (void) viewDidLoad {
[Super viewDidLoad];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithTitle: @ point toevoegen in kaart stijl: UIBarButtonItemStylePlain doel: zelf actie: @ selector (addPushed)];
[Self.navigationItem setRightBarButtonItem: barButton];
[BarButton vrijgave];
mapView = [[MKMapView VERD] initWithFrame: CGRectMake (0.0,0.0, self.view.frame.size.width, self.view.frame.size.height)];
mapView.showsUserLocation = FALSE;
mapView.delegate = zelf;
[Self.view insertSubview: mapView atIndex: 0];
[MapView vrijgave];
}
- (void) addPushed {
MKCoordinateRegion reg = mapView.region;
[Zelf storeLocationInfo: reg.center titel: @ prijs ondertitel: @ title index: 1];
}
- (void) dealloc {
[Super dealloc];
}
MyMark.h
#import <Foundation / Foundation.h>
#import <MapKit / MapKit.h>
@interface MyMark: NSObject <MKAnnotation> {
CLLocationCoordinate2D coördineren;
NSString * titel;
NSString * ondertiteling;
int index;
}
@ eigenschap (nonatomic, alleen lezen) CLLocationCoordinate2D coördineren;
@ eigenschap (nonatomic, alleen lezen) int index;
@ eigenschap (nonatomic behouden) NSString * titel;
@ eigenschap (nonatomic behouden) NSString * ondertiteling;
- (id) initWithCoordinate: (CLLocationCoordinate2D) coördineren;
- (id) setCoordinate: (CLLocationCoordinate2D) coördineren;
- (id) setTitle: (NSString *) t ondertiteling: (NSString *) st index: (int) i;
@einde
MyMark.m
#import MyMark.h
@implementation MyMark
@ synthetiseren coördineren index;
@ synthetiseren titel, ondertitel;
- (id) initWithCoordinate: (CLLocationCoordinate2D) c {
coördineren = c;
NSLog (@ % f% f, c.latitude, c.longitude);
terugkeer zelf;
}
- (id) setCoordinate: (CLLocationCoordinate2D) c {
coördineren = c;
NSLog (@ % f% f, c.latitude, c.longitude);
terugkeer zelf;
}
- (id) setTitle: (NSString *) t ondertiteling: (NSString *) st index: (int) i {
self.title = t;
self.subtitle = st;
index = i;
terugkeer zelf;
}
- (void) dealloc {
[Title vrijgave];
[Vrijgave ondertitel];
[Super dealloc];
}













