Passing places and coordinates of a UITableView to a MapKit

0

This is my first App, and basically consists of making locations available in a UITable (app entry point) and querying them in a MapKit (StoryBoard model). How can I make the call?

I am 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 in 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?           

    }
}
    
asked by anonymous 02.02.2017 / 18:55

1 answer

0

You can send the object by UISegue by 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 catch 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;
    }
}
    
31.03.2017 / 01:30