2

I have a tabBarView controller and a TableViewController. When I click on a row I wan to go to another Tab which is UIViewController with Map:

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

This is how I go to the 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];
}

The problem is Map does not get update when I go to the page again. When I tried it with PushSegue, it works. but how can I make it work with TabBar?

Ali
  • 9,800
  • 19
  • 72
  • 152

2 Answers2

0

Well, it looks like you commented out your call to -setMap, which means that when the view loads, nothing of interest is going to happen. Was that intentional?

Jonathan Grynspan
  • 43,286
  • 8
  • 74
  • 104
0

I figured out how can I pass the data over tab bars. You can find more descriptions in these links:

iPhone: How to Pass Data Between Several Viewcontrollers in a Tabbar App

Passing a managedObjectContext through to a UITabBarController's views

Also this tutorial is useful.

Community
  • 1
  • 1
Ali
  • 9,800
  • 19
  • 72
  • 152