我有一个表格视图。当用户触摸时,app必须打开该地点的地图。 在第一次触摸时,它会打开一个空白地图,但第二次显示正确的注释。
在控制台上我收到错误:
“: CGImageCreateWithImageProvider: 图像尺寸无效:0 x 0.“图像尺寸无效: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];
}
它显示空的世界地图,没有缩放和注释。我究竟做错了什么。 感谢
答案 0 :(得分:2)
您正在尝试在推送视图控制器之前设置UI控件。在你试图设置它们时它们可能是零,所以设置没有效果,你得到一张空地图。
请尝试以下方法:
将JJ_MapAnnotation * anno添加为SecondViewController中的属性,并在推送视图控制器之前仅设置该属性。然后,在SecondViewController的viewDidAppear中,执行您当前在didSelectAtRowIndexPath中执行的操作(设置标题,添加注释,设置区域等)。