Pass locations and coordinates of a Uitableview to a Mapkit

Asked

Viewed 27 times

0

This is my first App and basically consists of providing locations in a Uitable (app entry point) and consulting them in a Mapkit (Storyboard model). How can I make the call?

I’m trying to use an Nsdictionary for the values in the table and then the Prepareforsegue method. Is it possible to include specific coordinates in the Dictionary or a separate Array? And how to specify in the Prepareforsegue method?

The code:

@implementation TableViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    _citySpots = @{@"Bars" : @[@"Hurricane", @"Black Swan", @"Texas"],
                       @"Clubs" : @[@"Electric Wizard", @"Offspring", @"The Tunnel"],
                       @"Restaurants" : @[@"Nando's", @"1/2 Burguer", @"Satellite"],
                       };

        _sectionTitles = [[_citySpots allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
    }

The Prepareforsegue method:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"spotsDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

        MapViewController *destViewController = segue.destinationViewController;

        NSString *sectionTitle = [_sectionTitles objectAtIndex:indexPath.section];

         NSArray *citySpots = [_citySpots objectForKey:sectionTitle];
             //coordenadas?           

    }
}

1 answer

0

You can send the object by UISegue by the method -tableView:didSelectRowAtIndexPath::

- (void) tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath {
    NSString *sectionTitle = [_sectionTitles objectAtIndex:indexPath.row]; // ou indexPath.section, eleja o correto
    [self performSegueWithIdentifier:@"SUA_SEGUE_AQUI" sender:sectionTitle];
}

And capture it in -prepareForSegue:sender::

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id) sender {
    if ([segue.identifier isEqualToString:@"SUA_SEGUE_AQUI"]) {
        MapViewController *destViewController = segue.destinationViewController;
        NSString *sectionTitle = (NSString *) sender;
        NSArray *citySpots = [_citySpots objectForKey:sectionTitle];
        destViewController.citySpots = citySpots;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.