首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mkannotation副标题

mkannotation副标题
EN

Stack Overflow用户
提问于 2012-08-21 15:42:18
回答 2查看 1.9K关注 0票数 1

我正在尝试将mkannotation添加到我的地图中,但是没有显示副标题(或者我不知道如何查看它,因为我有一台android设备,很难理解iphone的工作原理)

这是我的MapPoint.h:

代码语言:javascript
复制
@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:

代码语言:javascript
复制
@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中,我有:

代码语言:javascript
复制
MapPoint *mp = [[MapPoint alloc] initWithCoordinate:pointCoord title:@"This is the title" subTitle:@"This is the subtitle"];
[mv addAnnotation:mp];

当我触摸我的记号笔时,我只看到“这是标题:

我想我必须看到这是标题,这是小字体的副标题。

提前谢谢你

EN

回答 2

Stack Overflow用户

发布于 2012-08-21 16:55:51

您需要从自定义初始化方法调用[super init]

代码语言:javascript
复制
self = [super init];
if (self) {
  // your code
}
return self;

除此之外,提供一个subtitle属性应该足以显示副标题(正如您所猜到的,第二行文本具有较小的字体)。确保设置了proerty,并使用viewController上的NSLog进行检查。

另外,考虑去掉两行tabBar,因为它违反了Apple HIG。如果需要显示许多菜单声音,请考虑使用另一种设计模式,如“滑出”菜单。您可以使用this library

票数 3
EN

Stack Overflow用户

发布于 2012-08-21 17:07:24

我找到了,我错过了andramazz所说的,调用超级并添加这个方法:

代码语言:javascript
复制
- (NSString *)subtitle {
    return subTitle;
 }

谁能告诉我为什么这个方法是必要的,但它不在标题中?

谢谢!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12050308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档