0

MKPointAnnotationを拡張し、dealLinkというNSStringのプロパティを追加しようとしています。

正しく設定したと思いましたが、現時点では次のエラーが発生しています。

 Property 'dealLink' not found on object of type 'MKPointAnnotation *'

MapOffersViewController.mというビューコントローラーのコードは次のとおりです。

#pragma mark - Populate Map
- (void)populateMap:(MKMapView*)map withDeals:(NSArray*) deals
{
    NSLog(@"Deals " );
    for (NSDictionary *currentDeal in deals) {
        CLLocationCoordinate2D  ctrpoint;
        ctrpoint.latitude = [[[currentDeal objectForKey:@"coords"] objectForKey:@"lat"] doubleValue];
        ctrpoint.longitude =[[[currentDeal objectForKey:@"coords"] objectForKey:@"lng"] doubleValue];

        MKPointAnnotation  *dealAnnotation   = [[MKPointAnnotation  alloc] init];

        dealAnnotation.coordinate = ctrpoint;
        dealAnnotation.title = [currentDeal objectForKey:@"vendor"];
        **dealAnnotation.dealLink = [currentDeal objectForKey:@"link"];**

        NSDictionary *currDict = @{
        @"EUR": @"€",
        @"GBP": @"₤",
        @"USD": @"$",
        @"BRL": @"R$"
        };

        NSString *currName = [currentDeal objectForKey:@"currency"];
        NSString *currency = [currDict objectForKey:currName];

        dealAnnotation.subtitle = [NSString stringWithFormat:@"%@%i",currency,[[currentDeal objectForKey:@"price"] integerValue ]];

        NSLog(@"current deal id is %@",[currentDeal objectForKey:@"id"]);

        [map setDelegate:self];
        [map addAnnotation:dealAnnotation];
    }
}

MapAnnotation.hというこのクラスをインポートしています。

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapAnnotation : MKPointAnnotation
{
    NSString *title;
    NSString *subtitle;
    NSString *dealLink;
    CLLocationCoordinate2D coordinate;
}

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, retain) NSString *dealLink;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

- (id)initWithTitle:(NSString *)ttl subTitle:(NSString *)subttl dealLink:(NSString *)dealLnk andCoordinate:(CLLocationCoordinate2D)c2d;

@end

そしてそれは.mです:

#import "MapAnnotation.h"

@implementation MapAnnotation

@synthesize title,subtitle,dealLink,coordinate;

- (id)initWithTitle:(NSString *)ttl subTitle:(NSString *)subttl dealLink:(NSString *)dealLnk andCoordinate:(CLLocationCoordinate2D)c2d {
    title = ttl;
    subtitle = subttl;
    dealLink = dealLnk;
    coordinate = c2d;

    return self;
}

@end

助けてくれてありがとう

これを機能させるために、以下のCraigの回答とこの追加コードを使用しました。

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {


    NSLog(@"callout tapped from del method %@", dealUrl);

   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dealUrl]];

}


- (void)mapView:(MKMapView *)mapView1 didSelectAnnotationView:(MKAnnotationView *)mapView2
{
    MapAnnotation *annotation = mapView2.annotation;
    NSString *temp = annotation.dealLink;

    dealUrl = temp;

 //   NSLog(@"temp is %@", temp);

}
4

1 に答える 1

1

MKPointAnnotationを作成し、MapAnnotationsにのみ存在するdealLinkにアクセスしようとしています。MapAnnotationを作成する必要があります

....
ctrpoint.longitude =[[[currentDeal objectForKey:@"coords"] objectForKey:@"lng"] doubleValue];

MapAnnotation  *dealAnnotation   = [[MapAnnotation  alloc] init];

dealAnnotation.coordinate = ctrpoint;
....   
于 2013-02-28T19:53:19.067 に答える