0

長い緯度を生成するシングルトンがあります。それらをログに記録できますが、それらを取得できるようにしたいです。私は何を間違っていますか?

singleton.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];

}

codethatcallsthem.m

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

どうもありがとう。

4

1 に答える 1

2

プロパティが ivar 名と一致しません。

  1. いずれかの ivar を除外し、自動的に作成されたもの (_longt、_lat) を使用します。

  2. またはさらに良いのは、self.longt = および self.lat = と言うことです

  3. または悪い: @synthesize を使用して、プロパティが既存の ivar を使用するようにします。

-- 私は 2 でいいと思います。

于 2013-07-06T11:48:47.883 に答える