Ios 向MKUserTrackingBarButtonItem添加操作

Ios 向MKUserTrackingBarButtonItem添加操作,ios,ios7,mapkit,Ios,Ios7,Mapkit,使用Xcode 6 我的跟踪按钮在导航栏的右侧,它不会触发该方法,我不知道为什么,这应该是正确的方法 按钮本身是功能性的 - (void)viewDidLoad { [super viewDidLoad]; //location initial settings: firstLaunch = YES; self.mapView.delegate = self; [self.mapView setShowsUserLocation:YES];

使用Xcode 6

我的跟踪按钮在导航栏的右侧,它不会触发该方法,我不知道为什么,这应该是正确的方法

按钮本身是功能性的

- (void)viewDidLoad
{
    [super viewDidLoad];

    //location initial settings:
    firstLaunch = YES;
    self.mapView.delegate = self;

    [self.mapView setShowsUserLocation:YES];

    locationManager = [[CLLocationManager alloc] init];

    [locationManager setDelegate:self];

    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    currentCentre = self.mapView.centerCoordinate;
    //create a thread queue
    [self queryGooglePlaces: currentCentre];

    //navBar:

    MKUserTrackingBarButtonItem *trackButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:_mapView];
    [trackButton setTarget:self];
    [trackButton setAction:@selector(track:)];

    self.navigationItem.rightBarButtonItem = trackButton;
}

-(void) track: (id) sender {
    NSLog(@"clicked !");
}

我认为您不能以这种方式使用MKUserTrackingBarButtonItem——它已经有了一个目标,关联的地图视图和一个改变跟踪模式的操作。相反,我会查看-[MKMapViewDelegate mapView:didChangeUserTrackingMode:animated:],以便在单击按钮时响应贴图模式的更改

我不认为您可以以这种方式使用MKUserTrackingBarButtonItem-它已经有了一个目标关联的地图视图和一个改变跟踪模式的操作。相反,我会查看-[MKMapViewDelegate mapView:didChangeUserTrackingMode:animated:],以便在单击按钮时响应贴图模式的更改