J'ai une vue détaillée qui comprend trois UIButtons, chacun d'entre eux poussant une vue différente sur la pile. L'un des boutons est connecté à un MKMapView. Lorsque ce bouton est enfoncé, je dois envoyer les variables de latitude et de longitude de la vue détaillée à la vue cartographique. Je suis en train d'ajouter la déclaration de chaîne dans la IBAction:Comment puis-je transmettre les valeurs de latitude et de longitude de UIViewController à MKMapView?
- (IBAction)goToMapView {
MapViewController *mapController = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
mapController.mapAddress = self.address;
mapController.mapTitle = self.Title;
mapController.mapLat = self.lat;
mapController.mapLng = self.lng;
//Push the new view on the stack
[[self navigationController] pushViewController:mapController animated:YES];
[mapController release];
//mapController = nil;
}
Et sur mon fichier MapViewController.h je:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "DetailViewController.h"
#import "CourseAnnotation.h"
@class CourseAnnotation;
@interface MapViewController : UIViewController <MKMapViewDelegate>
{
IBOutlet MKMapView *mapView;
NSString *mapAddress;
NSString *mapTitle;
NSNumber *mapLat;
NSNumber *mapLng;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property (nonatomic, retain) NSString *mapAddress;
@property (nonatomic, retain) NSString *mapTitle;
@property (nonatomic, retain) NSNumber *mapLat;
@property (nonatomic, retain) NSNumber *mapLng;
@end
Et sur les parties pertinentes du MapViewController Fichier .m J'ai:
@synthesize mapView, mapAddress, mapTitle, mapLat, mapLng;
- (void)viewDidLoad
{
[super viewDidLoad];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = mapLat; //40.105085;
region.center.longitude = mapLng; //-83.005237;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
CourseAnnotation *ann = [[CourseAnnotation alloc] init];
ann.title = mapTitle;
ann.subtitle = mapAddress;
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}
Mais j'obtiens ceci quand j'essaye de construire: 'erreur: types incompatibles dans assig nment 'pour les variables lat et lng. Donc, mes questions sont: est-ce que je vais passer les variables d'une vue à l'autre de la bonne façon? Et le MKMapView accepte-t-il la latitude et la longitude comme une chaîne ou un nombre?