作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 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;
}
- (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];
}
PushSegue
, 有用。但我怎样才能使它与 TabBar 一起工作?
最佳答案
好吧,您似乎已注释掉您对 -setMap
的调用,这意味着当 View 加载时,不会发生任何感兴趣的事情。那是故意的吗?
关于iphone - 当我们导航到 MapTabBar 时重新加载 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13400390/
我有一个 tabBarView Controller 和一个 TableViewController。当我单击一行时,我想转到另一个选项卡,即带有 map 的 UIViewController: -
我是一名优秀的程序员,十分优秀!