ios - Subclass MKAnnotation and add objects to MapView -
i seek subclass mkannotation
protocol can add together own store
object mapview
annotation
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
store.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]; homecoming thecoordinate; } @end
viewcontroller.m (where seek add together store object 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]; }
error:
-[store setcoordinate:]: unrecognized selector sent instance 0x1742a9600 2014-10-29 14:54:01.992 testmap[10417:2312661] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[store setcoordinate:]: unrecognized selector sent instance 0x1742a9600'
question:
how can add together store object annotation mapview? how set title , subtitle of annotation?
your store class needs cllocationcoordinate2d
property named coordinate
if plan on not having custom setters , getters, or setters , getters property if plan on having custom ones.
title , subtitle set similarily, either add together properties named title , subtitle , used automatically, or add together getters these 2 homecoming whatever text like.
there's more detail here.
p.s. ever since got arc, there no need synthesize of properties, line can ommited. additionally, might want consider not using ivars, , moving properties .m file in interface extension, unless need them public.
ios objective-c iphone xcode mkannotation
No comments:
Post a Comment