2014-03-03 78 views
0

我是Objective-C的新手,我正在使用Google Maps SDK for iOS。 我想在单击标记时看到NSLog输出。我用以下GMSMapViewDelegate的委托方法:GMSMapViewDelegate方法不工作

  • -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 

回答

3

您正在设置mapView_.delegate = self;之前mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; mapView_将在您设置委托时为零;在实例之后设置委托,以便您的实例变量不为零。