如何将一个方法中定义的变量值检索到另一个目标中



我有一个方法

- (void)locationUpdate:(CLLocation *)location {
self.locationLatitude = [NSString stringWithFormat:@"%f", location.coordinate.latitude] ;
self.locationLongitude = [NSString stringWithFormat:@"%f", location.coordinate.longitude ];   

现在我想获得self的值。locationLatitude和self。但是我不希望methodOne调用locationUpdate:(CLLocation *)location method

-(void)methodOne{
NSLog(%@,Location.Latitude);//it should show coordinate.
}

另一个问题是我应该在哪里调用methodOne?我不想在locationUpdate方法中调用它。我想在viewDidLoad方法中调用它。但是当我在viewDidLoad中调用它时nslog显示null

您需要引用对象,使用self.

-(void)methodOne{
    NSLog(%@, self.locationLongitude);
}

最新更新