gpt4 book ai didi

iphone - 当我们导航到 MapTabBar 时重新加载 map

转载 作者:行者123 更新时间:2023-12-01 16:54:06 24 4
gpt4 key购买 nike

我有一个 tabBarView Controller 和一个 TableViewController。当我单击一行时,我想转到另一个选项卡,即带有 map 的 UIViewController:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if(storeName)
[self setMap];
}

- (void) setMap {

NSLog(@"Name:%@\n", storeName);
NSLog(@"Adress:%@\n", storeAddress);



self.indexMapView.delegate = self;

self.indexMapView.showsUserLocation = NO;

self.locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];

[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

[self.indexMapView setShowsUserLocation:YES];

CLLocationCoordinate2D location = [self getLocationFromAddressString:self.storeAddress];

NSLog(@"%g", location.latitude);

MapViewAnnotation *mapAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Store location" coordinate:location];
[self.indexMapView addAnnotation:mapAnnotation];

}

-(CLLocationCoordinate2D) getLocationFromAddressString:(NSString*) addressStr {

NSLog(@"FFF");

NSString *urlStr = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
[addressStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSError *error = nil;

NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlStr] encoding:NSUTF8StringEncoding error:&error];

NSArray *items = [locationStr componentsSeparatedByString:@","];

double lat = 0.0;
double lon = 0.0;

if([items count] >= 4 && [[items objectAtIndex:0] isEqualToString:@"200"]) {
lat = [[items objectAtIndex:2] doubleValue];
lon = [[items objectAtIndex:3] doubleValue];
}
else {
NSLog(@"Address, %@ not found: Error %@",addressStr, [items objectAtIndex:0]);
}

CLLocationCoordinate2D location;
location.latitude = lat;
location.longitude = lon;

return location;
}

这就是我去 MapViewController 的方式:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MapViewController *mapViewController = [[MapViewController alloc]init];

[mapViewController setStoreAddress:store.address];
[mapViewController setStoreName:store.name];
[mapViewController viewDidLoad];

[self.tabBarController setSelectedIndex:4];
}

问题是当我再次访问该页面时 map 没有更新。当我尝试使用 PushSegue , 有用。但我怎样才能使它与 TabBar 一起工作?

最佳答案

好吧,您似乎已注释掉您对 -setMap 的调用,这意味着当 View 加载时,不会发生任何感兴趣的事情。那是故意的吗?

关于iphone - 当我们导航到 MapTabBar 时重新加载 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13400390/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com