2013-10-29 42 views
0

我試圖訪問在我的MapAnnotation自定義註釋類中設置的「imageurl」屬性。然而,當試圖訪問它在annotationView方法,我得到一個錯誤自定義MKAnnotation類

沒有已知的實例方法選擇「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]; 
} 

回答

3

問題迎刃而解

鑄[視圖註釋]至(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]; 
}