1

I'm trying to add mkannotation to my map, but the subtitle is not shown (or I don't know how to view it, I have an android device, and it's hard understand how the iphone works)

This is my MapPoint.h:

@interface MapPoint : NSObject<MKAnnotation> {

NSString *title;
NSString *subTitle;
CLLocationCoordinate2D coordinate;

}

@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic,copy) NSString *title;
@property (nonatomic,copy) NSString *subTitle;

-(id) initWithCoordinate:(CLLocationCoordinate2D) c title:(NSString *) t subTitle:(NSString *) st;

@end

My MapPoint.m:

@implementation MapPoint

@synthesize title,coordinate,subTitle;

-(id) initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString*)t subTitle:(NSString *) st
{
coordinate = c;
[self setTitle:t];
[self setSubTitle:st];
return self;

}


@end

And in Map.m, I have:

MapPoint *mp = [[MapPoint alloc] initWithCoordinate:pointCoord title:@"This is the title" subTitle:@"This is the subtitle"];
[mv addAnnotation:mp];

I when i touch my marker, I only see "this is the title:

enter image description here

I suppose I have to see This is the title, and This is the subtitle with smaller font.

Thank you in advance

user1256477
  • 10,763
  • 7
  • 38
  • 62

2 Answers2

3

You need to call [super init] from your custom init method

self = [super init];
if (self) {
  // your code
}
return self;

beside that, providing a subtitle property should be enough to display the subtitle (as you guessed, a second line of text with smaller font). Make sure that the proerty is set, checking with NSLog on your viewController.

Also, consider getting rid of the two line tabBar since it's in violation of Apple HIG. If you need to display many menu voices, consider using another design pattern such as the Slide out menu. You can use this library

andreamazz
  • 4,256
  • 1
  • 20
  • 36
2

I found it, I missed what andramazz said, call the super and add this method:

- (NSString *)subtitle {
    return subTitle;
 }

Can somebody tell me why this method was necessary but it wasn't in the title?

Thanks!

user1256477
  • 10,763
  • 7
  • 38
  • 62
  • 1
    The property you defined was named `subTitle` (uppercase T) but the `MKAnnotation` protocol requires a property named `subtitle` (lowercase T). See http://stackoverflow.com/a/8743909/467105. –  Aug 21 '12 at 12:17