0
@property NSArray* restaurants;

@end

@implementation RestaurantsTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self requestRestaurants];
}

- (void)requestRestaurants {
    NSString *urlString = @"https://s3-us-west-2.amazonaws.com/samwell.party/yasminucla/restaurants.json";
    NSURL *url = [NSURL URLWithString:urlString];

    NSData *restaurantData = [NSData dataWithContentsOfURL:url];

    self.restaurants = [NSJSONSerialization JSONObjectWithData:restaurantData
                                                       options:NSJSONReadingAllowFragments
                                                         error:nil];
    [self.tableView reloadData];
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.restaurants count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

    NSInteger index = indexPath.row; // Get the row that we're at
    NSString* restaurant = self.restaurants[index]; // Get the name of the restaurant for the row from the array
    cell.textLabel.text = restaurant; // Set the cell text to be the name of the restaurant

    return cell;
}

@end

I have a UITableView Controller embedded in a TabViewController in the storyboard and added cells to the table view programatically. The cells have objects downloaded from a .json file from the internet. I would like to push a mapKit view to each individual cell when it is clicked, but Im not sure how to do it, as I cannot connect the cells individually in the storyboard.

Kosuke Ogawa
  • 7,383
  • 3
  • 31
  • 52
Yaz
  • 15
  • 2

2 Answers2

0

You need to use didSelectRowAtIndexPath and performSegueWithIdentifier.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"yourSegue" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    UIViewController *mapViewController = segue.destinationViewController;
    NSString* restaurant = self.restaurants[index];
    mapViewController.title = restaurant;
}

See also: How to make a push segue when a UITableViewCell is selected

From View Controller to View Controlle!

Kosuke Ogawa
  • 7,383
  • 3
  • 31
  • 52
0

Your Response

    self.storyboard    =      [
                             "Mr. Chow",
                             "Panera Bread",
                             "Il Pastaio",
                             "Jinky's Cafe",
                             "Kazu Nori",
                             "Happy Days"
                              ]

Add a class of name is MapViewController Then make a property for passing the json data

 #import <UIKit/UIKit.h>

 @interface MapViewController : UIViewController
 @property(nonatomic,strong)NSString*PassVarible;

 @end

After Adding Write code your initial class

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      MapViewController*vc=[self.storyboard instantiateViewControllerWithIdentifier:@"MapViewController"];
      vc.PassVarible=[self.restaurants objectAtIndex:indexPath.row];
      [self.navigationController pushViewController:vc animated:YES];
  }
Vikas Rajput
  • 1,754
  • 1
  • 14
  • 26