无法读取Objective C中的类成员值

时间:2013-10-07 21:41:11

标签: objective-c

我正在尝试用示例来学习Objective C,现在我遇到了以下问题。我有一个代码:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface ViewController :  UIViewController <MKMapViewDelegate> {
IBOutlet MKMapView *mapView;

MKPointAnnotation* startPoint;
MKPointAnnotation* endPoint;

double startPointLat;
double startPointLon;
double endPointLat;
double endPointLon;
}
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
- (IBAction)findPressed:(id)sender;

@end

并实施:

- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;

// Add an annotation
startPoint = [[MKPointAnnotation alloc] init];
startPoint.coordinate = CLLocationCoordinate2DMake(0, 0);
startPoint.title = @"Start point";

endPoint = [[MKPointAnnotation alloc] init];
endPoint.coordinate = CLLocationCoordinate2DMake(10, 10);
endPoint.title = @"End point";

startPointLat = 0;
startPointLon = 0;
endPointLat = 10;
endPointLon = 10;

[self.mapView addAnnotation:startPoint];
[self.mapView addAnnotation:endPoint];

NSLog(@"%@, %@ -> %@, %@", startPointLat, self->startPointLon, self->endPointLat, self->endPointLon);
}

但是日志输出中的值为空。怎么了?

1 个答案:

答案 0 :(得分:5)

格式说明符“%@”用于对象,但这里的变量是双精度数。你想要“%f”。