我正在尝试将mkannotation添加到我的地图中,但是没有显示副标题(或者我不知道如何查看它,因为我有一台android设备,很难理解iphone的工作原理)
这是我的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我的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在Map.m中,我有:
MapPoint *mp = [[MapPoint alloc] initWithCoordinate:pointCoord title:@"This is the title" subTitle:@"This is the subtitle"];
[mv addAnnotation:mp];当我触摸我的记号笔时,我只看到“这是标题:

我想我必须看到这是标题,这是小字体的副标题。
提前谢谢你
发布于 2012-08-21 16:55:51
您需要从自定义初始化方法调用[super init]
self = [super init];
if (self) {
// your code
}
return self;除此之外,提供一个subtitle属性应该足以显示副标题(正如您所猜到的,第二行文本具有较小的字体)。确保设置了proerty,并使用viewController上的NSLog进行检查。
另外,考虑去掉两行tabBar,因为它违反了Apple HIG。如果需要显示许多菜单声音,请考虑使用另一种设计模式,如“滑出”菜单。您可以使用this library
发布于 2012-08-21 17:07:24
我找到了,我错过了andramazz所说的,调用超级并添加这个方法:
- (NSString *)subtitle {
return subTitle;
}谁能告诉我为什么这个方法是必要的,但它不在标题中?
谢谢!
https://stackoverflow.com/questions/12050308
复制相似问题