0

Are there any other fields that can be added to a MapAnnotation other than setTitle and setSubtitle? I want to add more information to it than just 2 bits of data.

EDIT

I am looking for iOS 7+ info on this.

Sam Cromer
  • 687
  • 3
  • 12
  • 31
  • 1
    possible duplicate of http://stackoverflow.com/questions/2342070/how-to-add-more-details-in-mkannotation-in-ios – foggzilla Feb 07 '14 at 14:51
  • Problem is the link to the tutorial is broken and it's not for iOS 7. – Sam Cromer Feb 07 '14 at 15:04
  • I think that duplicate link by foggzilla confuses the MKAnnotation protocol which is a template for your _model_ class with the MKAnnotationView which is the _view_ for your model class. The accepted answer here is correct. –  Feb 09 '14 at 13:11

1 Answers1

1

MKAnnotation is a protocol, so you can make any class into an annotation by making it conform to that protocol. As long as that class fulfils the requirements (title, subtitle and coordinate) you can add whatever properties you want. None of this has changed in iOS 7.

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

@interface Shop : NSObject <MKAnnotation, NSCoding>

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

@property (nonatomic, assign) int shopId;
@property (nonatomic, copy) NSString *shopOwnerName;

@end
nevan king
  • 112,709
  • 45
  • 203
  • 241