2014-03-03 113 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_將在您設置委託時爲零;在實例之後設置委託,以便您的實例變量不爲零。