Mapview 不显示来自引脚注释的标题或副标题

Posted

技术标签:

【中文标题】Mapview 不显示来自引脚注释的标题或副标题【英文标题】:Mapview not displaying Title or subtitle from pin annotation 【发布时间】:2013-01-22 04:02:10 【问题描述】:

点击注释图钉时应用返回错误。但是它不会崩溃。它只是不显示标题或副标题。

错误是 (lldb) 然后列出一串数字,例如 0x3516b5a0。

plist 示例:

<dict>
        <key>cellName</key>
        <string>Abingdon Lodge No. 48</string>
        <key>cellSubtitle</key>
        <string>Abingdon, VA</string>
        <key>address</key>
        <string>325 W Main Street Abingdon, Virginia 24210</string>
        <key>latitude</key>
        <real>36.708649</real>
        <key>longitude</key>
        <real>-81.981184</real>
        <key>webSite</key>
        <string>http://www.grandlodgeofvirginia.org/lodges/48/</string>
        <key>statedCom</key>
        <string>Abingdon Lodge No. 48 holds it&apos;s stated communication on the 2nd Monday of the month at 7:30 PM. If there are any exceptions to the regular meeting day or time, they are posted on the Lodge website.</string>
        <key>history</key>
        <string>According to the earliest records the Abingdon Lodge had its origin “At a meeting held at the house of James White in the town.</string>
    </dict>

MapviewController.M

- (void)viewDidLoad


    // Do any additional setup after loading the view, typiclly from a nib.
    //Create the region
    MKCoordinateRegion myRegion;

    //Center
    CLLocationCoordinate2D center;
    center.latitude = VA_LATITUDE;
    center.longitude = VA_LONGITUDE;

    //Span
    MKCoordinateSpan span;
    span.latitudeDelta = THE_SPAN;
    span.longitudeDelta = THE_SPAN;

    myRegion.center = center;
    myRegion.span = span;


    //Set our mapView
    [myMapView setRegion:myRegion animated:YES];


    NSString *path = [[NSBundle mainBundle] pathForResource:@"lodges" ofType:@"plist"];
    NSMutableArray* lodgelist = [[NSMutableArray alloc] initWithContentsOfFile:path];

    for(int i = 0; i < [lodgelist count]; i++) 
        float realLatitude = [[[lodgelist objectAtIndex:i] objectForKey:@"latitude"] floatValue];
        float realLongitude = [[[lodgelist objectAtIndex:i] objectForKey:@"longitude"] floatValue];

        CLLocationCoordinate2D mypoint;
        mypoint.latitude = realLatitude;
        mypoint.longitude = realLongitude;
        Annotation *lodgepoint =[Annotation alloc];
        lodgepoint.coordinate = mypoint;
        lodgepoint.title = [[lodgelist objectAtIndex:i] objectForKey:@"cellName"];
        lodgepoint.subtitle = [[lodgelist objectAtIndex:i] objectForKey:@"cellSubtitle"];
        [self.myMapView addAnnotation:lodgepoint];


    





- (void)didReceiveMemoryWarning

    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.


@end

MapViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface AWCMapViewController : UIViewController

@property (strong, nonatomic) IBOutlet MKMapView *myMapView;

-(IBAction)findmylocation:(id)sender;
-(IBAction)setmaptype:(id)sender;

@property (strong, nonatomic) NSArray *tabledata;


@end

【问题讨论】:

我认为您需要实现注释的方法,如 viewForAnnotation、didSelectAnnotation 和 canShowCallout 属性应设置为 YES 以显示标注。 试试我的答案。它应该可以工作 谢谢大家,我回家后试试这个.. 【参考方案1】:

在你的

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation

在您的MKAnnottionView下添加以下内容

customPinView.canShowCallout=YES;

问候

【讨论】:

CLLocationCoordinate2D mypoint; mypoint.latitude = realLatitude; mypoint.longitude = 真实经度;注解 *lodgepoint =[注解分配]; lodgepoint.coordinate = mypoint; lodgepoint.title = [[lodgelist objectAtIndex:i] objectForKey:@"cellName"]; lodgepoint.subtitle = [[lodgelist objectAtIndex:i] objectForKey:@"cellSubtitle"]; [self.myMapView addAnnotation:lodgepoint]; -(MKAnnotationView *)myMapView:(MKMapView *)mV viewForAnnotation:(id )annotation MKPinAnnotationView *pinView = nil; pinView.pinColor = MKPinAnnotationColorPurple; pinView.canShowCallout = YES; pinView.animatesDrop = YES;返回 pinView; 无法识别的选择器发送到实例 0x20872620 你的 UIView 的用户交互启用了吗? 是的,更换 Mapkit VC 后,它不显示字幕,但不显示磁贴.. 标题标记为卫星......这个问题让我发疯了【参考方案2】:
@interface Annotation : NSObject <MKAnnotation>

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

我不得不将标题从分配更改为复制。 :P

【讨论】:

以上是关于Mapview 不显示来自引脚注释的标题或副标题的主要内容,如果未能解决你的问题,请参考以下文章

在 Swift 中的同一个 mapView 中分配多个注释 pinColors?

Swift MKMapView 引脚注释问题

单击时 MapView 自定义引脚不显示详细信息

添加自定义注释引脚

iOS:地图视图注释未显示针脚

显示选定半径的 MapView 注释