0

私は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);
}

ただし、ログ出力の値は null です。どうしたの?

4

1 に答える 1

5

書式指定子 "%@" はオブジェクト用ですが、ここの変数は double です。代わりに「%f」が必要です。

于 2013-10-07T21:49:52.510 に答える