3つのUIButtonを含む詳細ビューがあり、それぞれが異なるビューをスタックにプッシュします。ボタンの1つはMKMapViewに接続されています。そのボタンが押されたら、緯度と経度の変数を詳細ビューからマップビューに送信する必要があります。IBActionに文字列宣言を追加しようとしています。
- (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;
}
そして、私のMapViewController.hファイルには次のものがあります。
#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
そして、MapViewController.mファイルの関連部分には次のものがあります。
@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];
}
しかし、次のようにビルドしようとすると、次のようになります。'エラー:lat変数とlng変数の両方に対して'互換性のない型が割り当てられています。だから私の質問は、変数をあるビューから別のビューに正しい方法で渡すことについてですか?また、MKMapViewは緯度と経度を文字列または数値として受け入れますか?