我有一个产生长,拉特的单身人士。我可以记录它们但希望能够得到它们。我做错了什么?
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 - long,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];
非常感谢。
答案 0 :(得分:2)
您的房产与您的ivar名称不符..
让ivars离开并使用自动创建的(_longt,_lat)
或者更好的是说self.longt = and self.lat =
OR bad:使用@synthesize使属性使用现有的ivars
- 我会选择2。