【发布时间】:2014-10-29 13:59:32
【问题描述】:
我尝试将MKAnnotation 协议子类化,以便将我自己的Store 对象添加到MapView 作为注解
Store.h:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface Store : NSObject <MKAnnotation> {
NSString *storeType;
NSString *storeName;
NSString *storeAddress;
NSString *storeZip;
NSString *storeCity;
NSString *storeLinks;
NSString *storeBrands;
UIImage *storePicture;
NSString *storeDescription;
NSString *storeLatitude;
NSString *storeLongitude;
}
@property (nonatomic, retain) NSString *storeType;
@property (nonatomic, retain) NSString *storeName;
@property (nonatomic, retain) NSString *storeAddress;
@property (nonatomic, retain) NSString *storeZip;
@property (nonatomic, retain) NSString *storeCity;
@property (nonatomic, retain) NSString *storeLinks;
@property (nonatomic, retain) NSString *storeBrands;
@property (nonatomic, retain) UIImage *storePicture;
@property (nonatomic, retain) NSString *storeDescription;
@property (nonatomic, retain) NSString *storeLatitude;
@property (nonatomic, retain) NSString *storeLongitude;
@end
商店.m:
#import "Store.h"
@implementation Store
@synthesize storeType, storeName, storeAddress, storeBrands, storeCity, storeLatitude, storeLinks, storeLongitude, storeZip, storePicture, storeDescription;
- (CLLocationCoordinate2D)coordinate
{
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = [self.storeLatitude doubleValue];
theCoordinate.longitude = [self.storeLongitude doubleValue];
return theCoordinate;
}
@end
ViewController.m(我尝试将 Store 对象作为 Annotation 添加到 MapView:
for(Store *store in allStores) {
NSString *location = [store storeAddress];
location = [location stringByAppendingFormat:@", "];
location = [location stringByAppendingFormat:[store storeZip]];
location = [location stringByAppendingFormat:@" "];
location = [location stringByAppendingFormat:[store storeCity]];
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = [[store storeLatitude] floatValue];
annotationCoord.longitude = [[store storeLongitude] floatValue];
store.coordinate = annotationCoord;
[self.mapView addAnnotation:store];
}
错误:
-[Store setCoordinate:]: unrecognized selector sent to instance 0x1742a9600
2014-10-29 14:54:01.992 TestMap[10417:2312661] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Store setCoordinate:]: unrecognized selector sent to instance 0x1742a9600'
问题:
- 如何将 Store 对象作为 Annotation 添加到 MapView?
- 如何设置注释的标题和副标题?
【问题讨论】:
标签: ios objective-c iphone xcode mkannotation