都市と州の情報を MKAnnotation に追加しようとしていますが、注釈に追加する前にデータが消去されています。これが私の現在のコードです(簡単にするために、懸念のあるセクション/部分のみを示しています):
実装中:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
[self setCity:[placemark locality] andState:[placemark administrativeArea]];
}];
NSLog(@"Location 1: %@, %@", city, state);
MapPoint *mp = [[MapPoint alloc] initWithCoordinate:[newLocation coordinate]
title:[locationTitleField text]
date:[dateFormat stringFromDate:today]];
[mapView addAnnotation:mp];
}
- (void)setCity:(NSString *)c andState:(NSString *)s
{
[self setCity:c];
[city retain];
[self setState:s];
[state retain];
NSLog(@"Location 2: %@, %@", city, state);
}
インターフェイスで:
@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate, MKMapViewDelegate>
{
CLLocationManager *locationManager;
IBOutlet MKMapView *mapView;
NSString *city;
NSString *state;
}
@property (strong, nonatomic) IBOutlet UIWindow *window;
@property (nonatomic, copy) NSString *city;
@property (nonatomic, copy) NSString *state;
- (void)setCity:(NSString *)c andState:(NSString *)s;
@end
場所 1 は (null), (null) を印刷し、場所 2 はカリフォルニア州サンフランシスコを印刷します。アノテーションで使用する前に、これらのプロパティからデータが消去されるのはなぜですか?
どうもありがとう...