开发者

Iphone MapView loads on second time

I have a table view. When a user touches, app has to open a map of that place. On the first touch it opens an empty map but on the second time it show annotation which is correct.

On the console i'm getting an error:

": CGImageCreateWithImageProvider: invalid image size: 0 x 0."invalid image size: 0 x 0."

Here is my code where i push map开发者_如何学C view.

- (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];
             }

it shows empty world map without zooming and annotations on it. What am i doing wrong. Thanks


You're trying to set UI controls before the view controller is pushed. They are probably nil at the point you're trying to set them so the settings have no effect and you get an empty map.

Try the following:
Add JJ_MapAnnotation *anno as a property in the SecondViewController and set only that before pushing the view controller. Then, in the SecondViewController's viewDidAppear, do the stuff you're currently doing in the didSelectAtRowIndexPath (setting the title, adding the annotation, setting the region, etc).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜