我在 RootViewController.m 上有一个选项卡。该选项卡有 2 个按钮。单击后的第一个按钮将转到带有 mapView 的 CorpViewcontroller。当我第一次尝试点击第一个按钮时,地图是空白的,底部有谷歌标签。我必须单击返回,然后再次单击按钮,然后地图就会显示出来。是否可以始终在第一次单击按钮时显示地图?
我的 rootViewController.m 进入第二个屏幕:
[self.navigationController pushViewController:self.corpController animated:YES];
名为 corpViewController 的第二个屏幕具有以下代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Set Remote Location";
self.jsonData = [[NSMutableData alloc] init];
mapView.showsUserLocation = YES;
//Setup the double tap gesture for getting the remote location..
UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleGesture:)];
tgr.numberOfTapsRequired = 2;
tgr.numberOfTouchesRequired = 1;
[mapView addGestureRecognizer:tgr];
mapView.delegate = self;
NSLog(@"viewDidLoad done");
}
- (void)viewWillAppear:(BOOL)animated {
NSLog(@"viewWillAppear");
appDelegate = (NBSAppDelegate *)[[UIApplication sharedApplication] delegate];
double curLat = [appDelegate.curLat doubleValue];
MKUserLocation *userLocation = mapView.userLocation;
double miles = 10.0;
double scalingFactor = ABS( (cos(2 * M_PI * curLat / 360.0) ));
MKCoordinateSpan span;
span.latitudeDelta = miles/69.0;
span.longitudeDelta = miles/(scalingFactor * 69.0);
MKCoordinateRegion region2;
region2.span = span;
region2.center = userLocation.coordinate;
[mapView setRegion:region2 animated:YES];
NSLog(@"viewWillAppear done..");
}
请指教。
谢谢