Я пытаюсь добавить субтитры к моему MKAnnotation, потянув его из массива JSON. Я могу получить заголовок и координировать с моим контроллером вида, как показано ниже, но я не могу понять, что делать, чтобы получить субтитры, которые нужно вытащить из ключа JSON «cityName». Любая помощь будет замечательной! Спасибо!Pull MKAnnotation Subtitle from JSON Array
MapViewController.m
location.latitude = [dictionary[@"placeLatitude"] doubleValue];
location.longitude = [dictionary[@"placeLongitude"] doubleValue];
newAnnotation = [[MapViewAnnotation alloc] initWithTitle:dictionary[@"placeName"]
andCoordinate:location];
MapViewAnnotation.h
@interface MapViewAnnotation : NSObject <MKAnnotation> {
NSString *title;
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *subtitle;
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d;
@end
MapViewAnnotation.m
#import "MapViewAnnotation.h"
@implementation MapViewAnnotation
@synthesize title, coordinate, subtitle;
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {
title = ttl;
coordinate = c2d;
subtitle = [SUBTITLE PULLED FROM JSON]
return self;
}
@end
с этой линии "- (ID) initWithTitle: (NSString *) ТТЛ andCoordinate: (CLLocationCoordinate2D) C2D" может» t Я указываю только переменную ttl и c2d? – Brandon
no, вы можете добавить свойство 'subtitle' тоже:' - (id) initWithTitle: (NSString *) ttl иCoordinate: (CLLocationCoordinate2D) c2d andSubtitle: (NSString *) subTitle'. Будьте осторожны, чтобы изменить имя метода в '.h', а также – Yaman
Спасибо Яману, это может быть новичком, но могу ли я передать другие строки? скажем, я хотел, чтобы пользовательский, который мог быть передан невидимо – Brandon