Iphone MapView第二次加载
问题描述:
我有一个表格视图。当用户触摸时,应用必须打开该地点的地图。 第一次触摸时会打开一张空白地图,但第二次显示的注释是正确的。Iphone MapView第二次加载
在控制台我得到一个错误:
": CGImageCreateWithImageProvider: invalid image size: 0 x 0."invalid image size: 0 x 0."
这里是我的代码,我推地图视图。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath { TabNavAppDelegate *appDelegate = (TabNavAppDelegate *)[[UIApplication sharedApplication] delegate]; JJ_MapAnnotation *anno = (JJ_MapAnnotation *) [depotsArray objectAtIndex:indexPath.row]; if(self.secondViewController ==nil) {
SecondViewController *secView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; self.secondViewController = secView; [secView release]; }
secondViewController.title = [NSString stringWithFormat:@"%@", [anno title]]; [secondViewController.map addAnnotation:anno];
MKCoordinateRegion region; region.center.latitude = anno.coordinate.latitude; region.center.longitude = anno.coordinate.longitude; region.span.latitudeDelta = 0.03; region.span.longitudeDelta = 0.03; [secondViewController.map setRegion:region]; NSLog(@"Distance: %@",[anno title]); /* CLLocationCoordinate2D pointACoordinate = [secondViewController.map.userLocation coordinate]; CLLocation
*pointALocation = [[CLLocation alloc] initWithLatitude:pointACoordinate.latitude longitude:pointACoordinate.longitude]; CLLocationCoordinate2D pointBCoordinate = [anno coordinate]; CLLocation *pointBLocation = [[CLLocation alloc] initWithLatitude:pointBCoordinate.latitude longitude:pointBCoordinate.longitude]; double distanceMeters = [pointBLocation getDistanceFrom:pointALocation];
NSLog(@"Distance: %d",distanceMeters/1000); */
[appDelegate.navController pushViewController:secondViewController animated:YES];
}
它显示没有缩放和注释的空白世界地图。我究竟做错了什么。 谢谢
答
你正试图在视图控制器被推动之前设置UI控件。他们可能在你尝试设置它们的时候没有任何作用,所以设置没有效果,你会得到一张空白的地图。
请尝试以下操作:
将JJ_MapAnnotation * anno添加为SecondViewController中的属性,并仅在推送视图控制器之前设置该属性。然后,在SecondViewController的viewDidAppear中,执行didSelectAtRowIndexPath中正在执行的操作(设置标题,添加注释,设置区域等)。
我发现错误是iOS 4.0中的一个错误。如果用户位置已打开,则会生成此消息。但我的问题仍在继续。第一次加载时,我只显示没有任何注释的世界地图。我必须做一些与viewDidLoad? – EnginBodur 2010-11-10 16:00:44