Objective c 获取委托方法内部的值而不是该方法外部的值

Objective c 获取委托方法内部的值而不是该方法外部的值,objective-c,mapkit,Objective C,Mapkit,我在这个委托方法的这边得到了长lat值,但在这个委托方法的外面没有。当我跳转到上一个类时,我希望在上一个类中使用此值 我确实声明了委托,但每次我拖动贴图时,它都会被调用,而我在上一个类中没有得到值。据我所知,您需要设置观察者对象,该对象正在观察坐标,并在新坐标出现时收到通知 在CLLocationManagerDelegate类中 -(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { /

我在这个委托方法的这边得到了长lat值,但在这个委托方法的外面没有。当我跳转到上一个类时,我希望在上一个类中使用此值


我确实声明了委托,但每次我拖动贴图时,它都会被调用,而我在上一个类中没有得到值。

据我所知,您需要设置观察者对象,该对象正在观察坐标,并在新坐标出现时收到通知

在CLLocationManagerDelegate类中

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{

    //[_mapview setMapType:MKMapTypeStandard];
    CLLocationCoordinate2D center = _mapview.centerCoordinate;
    double lat = center.latitude;
    double lng = center.longitude;
    NSString *str = [NSString stringWithFormat:@"%f",lat];
    NSString *str1 = [NSString stringWithFormat:@"%f",lng];
    _newlat = str;
    _newlong=str1;

    NSLog(@"%@ %@",_newlat,_newlong);
}
在上节课中。m:

-(void) setLocationObserver:(id) observer
{
   self.locationObserver = observer
}

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{

    //[_mapview setMapType:MKMapTypeStandard];
    CLLocationCoordinate2D center = _mapview.centerCoordinate;
    double lat = center.latitude;
    double lng = center.longitude;
    NSString *str = [NSString stringWithFormat:@"%f",lat];
    NSString *str1 = [NSString stringWithFormat:@"%f",lng];
    _newlat = str;
    _newlong=str1;

    if ([self.locationObserver respondsToSelector:@selector(setNewCoords:)
        [self.locationObserver setNewCoords:center];

    NSLog(@"%@ %@",_newlat,_newlong);
}

粗略的示例,但可能会有所帮助。

在delated类或main类中声明的\u newlat和long在哪里?这是在该类的.h文件中的main类中声明的。很抱歉,它不起作用。请告诉我如何将\u newlat和\u newlong从该方法中声明出来。您在这里,希望对我有所帮助。如果您有任何问题,请更具体地说明什么不起作用,以便我们能够解决。如果([self.locationObserver respondsToSelector:@selector(setNewCoords:)[self.locationObserver setNewCoords:center];这一行显示错误。请具体说明。什么类型的错误?错误消息是什么?
-(void)-(void) setNewCoords:(CLLocationCoordinate2D*) location
{
    self.myLocation = location;
    [self doSeomethingWithNewLocation]; // if you wish
}

-(void) doSomethingWithNewLocation
{
    NSString * _newlat = [NSString stringWithFormat:@"%f",self.myLocation.latitude];
    NSString * _newlong = [NSString stringWithFormat:@"%f",self.myLocation.longitude];
}