0

我正在尝试访问在我的 MapAnnotation 自定义注释类中设置的“imageurl”属性。但是,当尝试在 annotationView 方法中访问它时,出现错误

选择器“imageurl”没有已知的实例方法

如果我尝试标题、描述或副标题,它们就可以正常工作。

如何访问注解的 imageurl 属性。

MapAnnotation.h

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

@interface MapAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
NSString *description;
NSString *imageurl;
}

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, copy) NSString *description;
@property (nonatomic, copy) NSString *imageurl;
@end

MapViewController.m

#import "MapViewController.h"
#import "AppDelegate.h"
#import "MapDetailViewController.h"
#import "MapAnnotation.h"

@interface MapViewController ()
@end

MapViewController.m    // Set span to cover area
MKCoordinateSpan span = MKCoordinateSpanMake(0.5, 0.5);

// Set region
MKCoordinateRegion regionToDisplay = MKCoordinateRegionMake(center, span);
[self.nearbyMapView setRegion: regionToDisplay];

for (int i = 0; i < [[appDelegate offersFeeds] count]; i++)
{

    CLGeocoder *geocoder = [[CLGeocoder alloc] init];

    NSString *plotAddress = [[[appDelegate offersFeeds] objectAtIndex:i] valueForKey:@"addressline"];
    NSString *plotTitle = [[[appDelegate offersFeeds] objectAtIndex:i] valueForKey:@"title"];
    NSString *plotSubTitle = [[[appDelegate offersFeeds] objectAtIndex:i] valueForKey:@"subtitle"];
    NSString *plotDescription = [[[appDelegate offersFeeds] objectAtIndex:i] valueForKey:@"description"];
    NSString *plotImageurl = [[[appDelegate offersFeeds] objectAtIndex:i] valueForKey:@"imageurl"];

    [geocoder geocodeAddressString:plotAddress completionHandler:^(NSArray *placemarks, NSError *error) {
        if (placemarks && placemarks.count > 0)
        {
            CLPlacemark *topResult = [placemarks objectAtIndex:0];
            MKPlacemark *placemark = [[MKPlacemark alloc]initWithPlacemark:topResult];


            MapAnnotation *annotation = [[MapAnnotation alloc] init];
            annotation.coordinate = placemark.location.coordinate;
            annotation.title = plotTitle;
            annotation.subtitle = plotSubTitle;
            annotation.description = plotDescription;
            annotation.imageurl = plotImageurl;
            [self.nearbyMapView addAnnotation:annotation];
        }
    }];
}
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MapAnnotation class]])
{
    MKPinAnnotationView *pinView = nil;

    static NSString *defaultPinID = @"identifier";
    pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if (pinView == nil)
    {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];

        pinView.pinColor = MKPinAnnotationColorRed;  //or Green or Purple

        pinView.enabled = YES;
        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;

        //Accessoryview for the annotation view in ios.
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

        //Add cobalt logo to the leftCallout
        pinView.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PinImage"]];

    }
    else
    {
        pinView.annotation = annotation;
    }

    return pinView;
}
return nil;
}

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

description = [[view annotation] description];
myimage = [[view annotation] imageurl]; //NOT WORKING

[self performSegueWithIdentifier:@"showDetail" sender:self];
}
4

1 回答 1

2

问题已解决

将 [视图注释] 转换为 (MapAnnotation *)

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
  MapAnnotation *annotation = = (MapAnnotation *)[view annotation];
  description = [annotation description];
  myimage = [annotation imageurl];

  [self performSegueWithIdentifier:@"showDetail" sender:self];
}
于 2013-10-29T17:16:32.247 回答