こんばんは、ユーザーがViewControllerのバーボタンを押したときにMapViewが読み込まれるアプリで問題が発生しています。MapViewControllerが読み込まれ、マップに正しいアノテーションが表示されます(ソースには表示されていません)が、アプリを最初に起動してMapViewを開いたときにstartregionが間違っています。[戻る]ボタンを1回押して、MapViewを再度開くと、startregionは正常です。初めて動作しません。
ログには、plistからロードされた正しい値が表示されます:47.572132および7.579397
私は2週間前にobjective-cのコーディングを始めたので、答えはできるだけ単純にしてください;-)
h。ファイル:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "DetailViewController.h"
#import "Annotation.h"
@interface MapViewController : UIViewController<CLLocationManagerDelegate> {
IBOutlet MKMapView *singlemapview;
}
@property (nonatomic, retain) NSArray *data;
@property int selectedBuilding;
@property (strong, nonatomic) CLLocationManager *location;
@property float longitude;
@property float latitude;
@end
m.File:
#import "MapViewController.h"
@interface MapViewController ()
@end
@implementation MapViewController
@synthesize data;
@synthesize selectedBuilding;
@synthesize location, latitude, longitude;
- (void)viewDidLoad
{
[super viewDidLoad];
NSDictionary *dataItem = [data objectAtIndex:selectedBuilding];
latitude = [[dataItem objectForKey:@"Latitude"] floatValue];
longitude = [[dataItem objectForKey:@"Longitude"] floatValue];
NSLog (@"%f",latitude);
NSLog (@"%f",longitude);
MKCoordinateRegion startregion = { {0.0, 0.0}, {0.0, 0.0} };
startregion.center.latitude = latitude;
startregion.center.longitude = longitude;
startregion.span.latitudeDelta = 0.005;
startregion.span.longitudeDelta = 0.005;
[singlemapview setMapType:MKMapTypeSatellite];
[singlemapview setZoomEnabled:YES];
[singlemapview setScrollEnabled:YES];
[singlemapview addAnnotation:singlebuilding];
[singlemapview setRegion:startregion];
}