2012-11-15 14 views
2

我有一個tabBarView控制器和一個TableViewController。當我點擊一排餘萬到另一個標籤是UIViewController的配圖:當我們導航到MapTabBar時重新加載地圖

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

問題是地圖沒有得到更新當我再次訪問頁面時。當我用PushSegue嘗試它時,它可以工作。但我如何使它與TabBar一起工作?

回答

0

嗯,它看起來像你的電話註釋,以-setMap,這意味着,當視圖加載,沒有興趣的事情發生。那是故意的嗎?

+0

我用setMap當用戶點擊另一個TableViewController中的一行。 – Ali

+0

檢查tableView的代碼:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)' – Ali

+0

啊,但你的看法*尚未加載*當你這樣做。 –

相關問題