我正在使用解析框架来收集类中的对象,并将它们显示在地图上。目前,注释标题显示"CreatedAt"字符串,字幕显示"坐标"。如何将标题和副标题更改为我设置的另一个PFObject ID?我的很多代码都基于Parse提供的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
通过用以下代码替换部分代码来修复它:
static NSString *dateFormatter = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSString alloc] init];
}
然后这个:
_title = [dateFormatter stringByAppendingString:self.object[@"Name"]];
_subtitle = [dateFormatter stringByAppendingString:self.object[@"Location"]];