/ / PFObject IDを解析してアノテーションのタイトルとサブタイトルをマッピングする - objective-c、parsing、mapkit、objectid

PFObject IDを解析して注釈のタイトルとサブタイトルをマッピングする - objective-c、parsing、mapkit、objectid

私はオブジェクトを収集するために構文解析フレームワークを使用しています地図上に表示することができます。現在、アノテーションタイトルには「CreatedAt」という文字列が表示され、字幕には「座標」が表示されます。私が設定した別のPFObject IDにタイトルとサブタイトルを変更するにはどうすればよいですか?パースが提供しているGeoLocationsアプリケーションに多くのコードを基づいています。コードは次のとおりです。

@interface GeoPointAnnotation()
@property (nonatomic, strong) PFObject *object;
@end

@implementation GeoPointAnnotation

- (id)initWithObject:(PFObject *)aObject {
self = [super init];
if (self) {
_object = aObject;

PFGeoPoint *geoPoint = self.object[@"coordinates"];
[self setGeoPoint:geoPoint];
}
return self;
}


- (void)setGeoPoint:(PFGeoPoint *)geoPoint {
_coordinate = CLLocationCoordinate2DMake(geoPoint.latitude, geoPoint.longitude);

static NSDateFormatter *dateFormatter = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeStyle = NSDateFormatterMediumStyle;
dateFormatter.dateStyle = NSDateFormatterMediumStyle;
}

static NSNumberFormatter *numberFormatter = nil;
if (numberFormatter == nil) {
numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
numberFormatter.maximumFractionDigits = 3;
}

_title = [dateFormatter stringForObjectValue:self.object.createdAt];
_subtitle = [NSString stringWithFormat:@"%@, %@", [numberFormatter stringFromNumber:[NSNumber numberWithDouble:geoPoint.latitude]],
[numberFormatter stringFromNumber:[NSNumber numberWithDouble:geoPoint.longitude]]];
}

@end

回答:

回答№1は0

これをいくつかのコードに置き換えることで修正しました:

 static NSString *dateFormatter = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSString alloc] init];

}

そして、これは:

_title = [dateFormatter stringByAppendingString:self.object[@"Name"]];

_subtitle = [dateFormatter stringByAppendingString:self.object[@"Location"]];