Xcode 将第三个属性添加到MKPointAnnotation/calloutAccessoryControlType
我一直在尝试将三点数据从MKMapView引脚传递到下一个视图控制器 现在,我可以使用calloutAccessoryControlTapped毫无问题地传递标题和副标题,但要传递第三个参数却非常困难 我一直在试图回答这个问题 我现在的代码是 在我的第一个ViewController.m文件中Xcode 将第三个属性添加到MKPointAnnotation/calloutAccessoryControlType,xcode,mkmapview,mkannotation,mkannotationview,Xcode,Mkmapview,Mkannotation,Mkannotationview,我一直在尝试将三点数据从MKMapView引脚传递到下一个视图控制器 现在,我可以使用calloutAccessoryControlTapped毫无问题地传递标题和副标题,但要传递第三个参数却非常困难 我一直在试图回答这个问题 我现在的代码是 在我的第一个ViewController.m文件中 #import "MapAnnotation.h" - (void)loadMapPins { for (int i=0; i<_feedItems1.count; i++){ Loc
#import "MapAnnotation.h"
- (void)loadMapPins {
for (int i=0; i<_feedItems1.count; i++){
Location *item = _feedItems1[i];
CLLocationCoordinate2D myCoordinate = {[item.latitude doubleValue], [item.longitude doubleValue]};
MapAnnotation *point = [[MapAnnotation alloc] init];
point.coordinate = myCoordinate;
point.title = item.firstname;
point.subtitle = [NSString stringWithFormat: @"%@", item.time];
point.dealLink = item.username;
[self.mapView addAnnotation:point];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation {
if (annotation == self.mapView.userLocation) return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* customPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
customPin.pinColor = MKPinAnnotationColorRed;
customPin.animatesDrop = YES;
customPin.canShowCallout = YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
customPin.rightCalloutAccessoryView = rightButton;
return customPin;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
NSLog(@"title = %@", view.annotation.title);
NSLog(@"subtitle = %@", view.annotation.subtitle);
NSLog(@"title = %@", view.annotation.dealLink);
}
但我总是在calloutAccessoryControlTapped方法中得到“在'id'类型的对象上找不到适当的dealLink”
有什么帮助或建议吗?试图通过三个参数真让我抓狂
#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
#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