gpt4 book ai didi

ios - GMSMapViewDelegate 方法不起作用

转载 作者:行者123 更新时间:2023-11-28 20:05:47 26 4
gpt4 key购买 nike

我是 Objective-C 的新手,正在使用适用于 iOS 的 Google Maps SDK。单击标记时,我想查看 NSLog 输出。我使用了 GMSMapViewDelegate 的以下委托(delegate)方法:

  • -mapView:didTapMarker:
  • -mapView:didTapInfoWindowOfMarker:但我没有看到任何有用的日志。

这是我的代码。您认为缺少什么?

#import "testViewController.h"

@interface testViewController ()

@end

@implementation testViewController{
GMSMapView *mapView_;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

mapView_.delegate = self;

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:41.12
longitude:29.05
zoom:12];
mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;


GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(41.12, 29.05);
marker.title = @"burdayım";
marker.map = mapView_;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
NSLog(@"ssssss");
}



- (void)dealloc {
[_V_map release];
[super dealloc];
}
@end

最佳答案

您正在设置 mapView_.delegate = self;在 mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; 设置委托(delegate)时,mapView_ 将为 nil;在实例化之后设置委托(delegate),这样您的实例变量就不是 nil。

关于ios - GMSMapViewDelegate 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22150091/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com