解析PFObject ID以映射注释标题&字幕

时间:2014-04-13 19:23:54

标签: objective-c parsing mapkit objectid

我正在使用解析框架来收集类中的对象并将其显示在地图上。目前,注释标题显示“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

1 个答案:

答案 0 :(得分:0)

通过用以下代码替换部分代码来修复它:

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

}

然后这个:

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

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