0

我有一个单例,可以生成长的,lats。我可以记录它们,但希望能够得到它们。我究竟做错了什么?

单例.h

@interface ClassLocationManager : NSObject <CLLocationManagerDelegate> {

    NSString *lat;
    NSString *longt;
}

@property (nonatomic, strong) CLLocationManager* locationManager;
@property (nonatomic, retain) NSString *lat;
@property (nonatomic, retain) NSString *longt;

+ (ClassLocationManager*) sharedSingleton; 

singleton.m - longt, lat 字符串在 -(id)init 中给出值

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    int degrees = newLocation.coordinate.latitude;
    double decimal = fabs(newLocation.coordinate.latitude - degrees);
    int minutes = decimal * 60;
    double seconds = decimal * 3600 - minutes * 60;
    lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds];
    NSLog(@" Current Latitude : %@",lat);

    degrees = newLocation.coordinate.longitude;
    decimal = fabs(newLocation.coordinate.longitude - degrees);
    minutes = decimal * 60;
    seconds = decimal * 3600 - minutes * 60;
    longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds];
    NSLog(@" Current Longitude : %@",longt);
    [manager stopUpdatingLocation];

}

调用它们的代码.m

NSString *formatted3 = [[ClassLocationManager sharedSingleton] longt];
NSString *formatted4 = [[ClassLocationManager sharedSingleton] lat];

非常感谢。

4

1 回答 1

2

您的属性与您的 ivar 名称不匹配..

  1. 要么留下 ivars 并使用自动创建的(_longt,_lat)

  2. 或者最好说 self.longt = 和 self.lat =

  3. 或不好:使用@synthesize 使属性使用现有的 ivars

——我会选择2。

于 2013-07-06T11:48:47.883 回答