【发布时间】:2015-03-27 08:46:49
【问题描述】:
您好,我正在尝试在地图视图中创建自定义注释。在 mapview 中,当用户单击要显示一些文本和按钮的图钉时,我在地图上有多个图钉制造商,因此尝试创建自定义注释视图,但它不起作用。
我的代码
#import <MapKit/MapKit.h>
#import <GoogleMaps/GoogleMaps.h>
@interface myviewcon : UIViewController<MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *mpview;
@end
viewdidload 中我的 MKPointAnnotation 代码
for (NSDictionary *dic in [jsonArray1 valueForKey:@"houses"]) {
MKPointAnnotation *annotation = [[MKPointAnnotation alloc]init];
NSString *name=[dic valueForKey:@"building_name"];
CLLocationCoordinate2D placeCoord;
placeCoord.latitude=[[dic objectForKey:@"lat"] doubleValue];
placeCoord.longitude=[[dic objectForKey:@"lng"] doubleValue];
[annotation setCoordinate:placeCoord];
[annotation setTitle:name];
[mpview addAnnotation:annotation];
}
还有我的自定义注释视图代码
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{
MKAnnotationView *anview = nil;
UIButton *btnViewVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
anview.rightCalloutAccessoryView=btnViewVenue;
anview.enabled = YES;
anview.canShowCallout = YES;
anview.multipleTouchEnabled = NO;
return anview;
}
当用户单击地图上的 pin 制造商时,我使用上面的代码制作 customview 我已经用文本和按钮制作了视图,我已经厌倦了这样但它不起作用我检查了代表正在调用的断点但它不起作用,请告诉如何解决这个问题。
提前致谢。
【问题讨论】:
-
唯一的问题似乎是在 viewForAnnotation 中,您没有创建视图。它被初始化为 nil,所以在它上面设置属性什么都不做。
标签: ios objective-c mkannotationview