Mapview不显示引脚注释中的标题或副标题 [英] Mapview not displaying Title or subtitle from pin annotation

查看:103
本文介绍了Mapview不显示引脚注释中的标题或副标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

App返回错误。但它不会崩溃。它只是没有显示标题或副标题。

App returns error when clicking the annotation pin. However it does not crash. It just does not show the title or subtitle.

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

Error is (lldb) then list a string of numbers like 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


推荐答案

@interface Annotation : NSObject <MKAnnotation>

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

我不得不将标题从分配更改为副本。 :P

I had to change the title from assign to copy. :P

这篇关于Mapview不显示引脚注释中的标题或副标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆