我想在上层视图控制器上单击“地图”按钮时在新视图控制器上显示引脚注释。如何在两个viewcontroller之间共享mapkit的变量?
因此,我对上级控制器的方法文件使用了“IBAction”方法,如下所示。 然后从属性列表中正常显示经纬度值(在NSLog中)。 但我无法在新的视图控制器上看到引脚注释。但是,如果我在新视图控制器(名为“位置”)上放置标记为“code for viewDidLoad”的代码,则可以看到引脚注释。 但是经度和纬度值只有0.00000。
我想两个视图控制器之间不共享变量。 请帮我解决这个问题。
- (IBAction) goAddView:(id)sender {
// the code for viewDidLoad
double myLat = [[drink objectForKey:lati_KEY] doubleValue];
double myLong = [[drink objectForKey:long_KEY] doubleValue]; CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = myLat;
theCoordinate.longitude = myLong;
NSLog(@"the latitude = %f",theCoordinate.latitude);
NSLog(@"the longitude = %f",theCoordinate.longitude);
myAnnotation *myAnnotation1=[[myAnnotation alloc] init];
myAnnotation1.coordinate=theCoordinate;
[email protected]"Destination";
[email protected]"in the city";
[self.mapView addAnnotation:myAnnotation1];
// the code end
location *lm= [[location alloc] initWithNibName:@"location" bundle:nil];
[self.navigationController pushViewController:lm animated:YES];
谢谢你非常喜欢你的答案。我需要学习更多。 :-)新年快乐,祝你好运。非常感谢。 – 2011-12-31 03:37:58