我正在尝试使用地图功能构建一个简单的导航控制器。我正在尝试将两个变量从 Root 视图带到 Detail 视图。一个有标签,有经度。
我从 Root 获取值到 Detail'd 视图,但在日志中它说:
- 2012-04-12 14:38:41.331 地图[80073:11603] 长:0.000000
- 2012-04-1214:38:41.331 地图 [80073:11603] 标签
- 2012-04-12 14:38:41.331 地图[80073:11603] 长:62.375702
其中 long 是经度,标签应该是标签的变量。我只传递了一个“长”变量,但无论如何总是先得到 0.00000,这会使地图显示错误的位置,并且标签根本不会显示任何内容..
几个小时以来,我一直试图找出问题所在,但似乎在代码或网络上找不到任何东西,因此非常感谢任何帮助。
RootViewController.m:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *term = @"Label";
float longi1 = 100.102321;
DetailViewController *svc = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
//send properties to your view controller
svc.term = term;
svc.longi = longi1;
//push it to the navigationController
[self.navigationController pushViewController:svc animated:YES];
[svc release];
svc = nil;
}
DetailViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(term);
NSLog(@"long: %f", longi);
coor.text = term;
float lati = 65.12414;
CLLocationCoordinate2D coord = {.latitude = lati, .longitude = longi};
MKCoordinateSpan span = {.latitudeDelta = 0.5, .longitudeDelta= 0.5};
MKCoordinateRegion region = {coord, span};
[mapView setRegion:region];
[self.view addSubview:mapView];
}