Dan*_*Dan 0 iphone mapkit mkannotation ios ios6
我的代码与问题相关:
注释.h文件
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface CityAnnotation : NSObject <MKAnnotation> {
NSString *name;
NSString *country;
CLLocationCoordinate2D coords;
}
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) NSString *country;
@property (nonatomic,assign) CLLocationCoordinate2D coords;
-(id)initWithTitle:(NSString *)cityname AndCountry:(NSString *)countryname AndCoords: (CLLocationCoordinate2D)coordinate;
@end
Run Code Online (Sandbox Code Playgroud)
注释.m文件
#import "CityAnnotation.h"
@implementation CityAnnotation
@synthesize name,country,coords;
-(id)initWithTitle:(NSString *)cityname AndCountry:(NSString *)countryname AndCoords:(CLLocationCoordinate2D)coordinate
{
self = [super init];
if (self){
self.name = cityname;
self.country = countryname;
self.coords = coordinate;
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
我导入到我的mapview:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "tableViewController.h"
#import "City.h"
#import "CityAnnotation.h"
Run Code Online (Sandbox Code Playgroud)
在视图控制器中添加注释.这是发生错误的地方[self.mapView addAnnotation:newAnnotation];
- (void)viewDidLoad
{
[super viewDidLoad];
CityAnnotation *newAnnotation = [[CityAnnotation alloc]initWithTitle:self.SelectedCity.name AndCountry:self.SelectedCity.country AndCoords:self.SelectedCity.location];
[self.mapView addAnnotation:newAnnotation];
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
-[CityAnnotation coordinate]: unrecognized selector sent to instance 0x85c7d70
2013-06-17 12:15:57.694 JsonTest[1769:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CityAnnotation coordinate]: unrecognized selector sent to instance 0x85c7d70'
Run Code Online (Sandbox Code Playgroud)
您的CityAnnotation类必须提供名为的属性/方法coordinate.有关详细信息,请参阅MKAnnotation协议参考.
您可以通过重命名coords属性来解决问题coordinate.
| 归档时间: |
|
| 查看次数: |
1310 次 |
| 最近记录: |