Pin无效

时间:2016-03-21 16:04:08

标签: ios objective-c xcode mapkit

我的地图在特定地点显示了一个图钉,但它没有显示图钉

这是代码

WadiRumViewControllerJordan.h

#import <UIKit/UIKit.h>
#include <MapKit/MapKit.h>

@interface WadiRumViewControllerJordan : UIViewController

@property (strong, nonatomic) IBOutlet MKMapView *WadiRumMapView;
@end

WadiRumViewControllerJordan.m

#import "WadiRumViewControllerJordan.h"
#import "WadiRumNSOjectPIN.h"

@interface WadiRumViewControllerJordan ()


@end
//Wadi Rum Coordinates
#define WadiRum_Latitude 29.537355
#define WidiRum_longtitude 35.415026

//Wadi Rum Span
#define WadiRumSpan 0.01f;


@implementation WadiRumViewControllerJordan
@synthesize WadiRumMapView;

- (void)viewDidLoad {
    [super viewDidLoad];
    //Create WadiRum Region
    MKCoordinateRegion WadiRumRegion;

    //Center
    CLLocationCoordinate2D center;
    center.latitude = WadiRum_Latitude;
    center.longitude = WidiRum_longtitude;

    //Span
    MKCoordinateSpan span;
    span.latitudeDelta = WadiRum_Latitude;
    span.longitudeDelta = WidiRum_longtitude;

    WadiRumRegion.center = center;
    WadiRumRegion.span = span;

    //Set our map
    [WadiRumMapView setRegion:WadiRumRegion animated:YES];

    //WadiRumNSObjectPIN
    //1. Create a coordinate for the use of WadiRum
    CLLocationCoordinate2D WadiRumLocation;
    WadiRumLocation.latitude = WadiRum_Latitude;
    WadiRumLocation.longitude = WidiRum_longtitude;

    WadiRumNSOjectPIN * WadiRumAnnitation = [[WadiRumNSOjectPIN alloc] init];
    WadiRumAnnitation.coordinate = WadiRumLocation;
    WadiRumAnnitation.title = @"Services";
    WadiRumAnnitation.subtitle = @"Desert";



    {[self.WadiRumMapView addAnnotation:WadiRumAnnitation];

    }
}

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



@end

WadiRumNSOjectPIN.h

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

@interface WadiRumNSOjectPIN : NSObject <MKAnnotation>

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

@end

WadiRumNSOjectPIN.m

#import "WadiRumNSOjectPIN.h"

@implementation WadiRumNSOjectPIN
@synthesize coordinate;

- (id)initWithLocation:(CLLocationCoordinate2D)coord {
    self = [super init];
    if (self) {
        coordinate = coord;
    }
    return self;
}

@synthesize coordinate, title, subtitle;

@end

我编辑了上面的代码,使其完全像我想要的,我在下面的图片中得到了这个错误

Picture

1 个答案:

答案 0 :(得分:1)

为了符合MKAnnotation,您必须拥有名为coordinatetitlesubtitle的属性。您添加了三个额外的属性,ttcoordinatetttitlettsubtitle,但MKAnnotation将忽略这些属性,并会查找coordinate,{ {1}}和title

您没有看到注释的关键原因是您在subtitle中设置了ttcoordinate。但viewDidLoad不会使用它,而是引用您合成的MKAnnotation属性,但从不设置。 (你确实有一个coordinate方法,它建议你更新initWithLocation,但你永远不会这样说。)

最重要的是,我建议将coordinatettcoordinatettitle重命名为ttsubtitlecoordinatetitle,并更新所有内容相应的那些引用,这应该解决所有问题。您可以退出subtitle行。