title: UITableView with JSON help
body: <p>I am trying to feed in some JSON data to my iPhone app, the data is coming in fine as I have NSLog's telling me so.</p>
  
  <p>The problem I am having is trying to get the results to show in a UITableView. I have a navigation controller underneath a tab bar controller, the navigation controller contains a table view controller which loads another NIB file with a table view connected to a class which is the delegate and data source delegate.</p>
  
  <p>I also need to categorize the results into sections - these being</p>
  
  <ul>
  <li>England</li>
  <li>Scotland</li>
  <li>Wales</li>
  <li>N.Ireland</li>
  </ul>
  
  <p>To get an idea of what JSON string I am using <a href="http://www.thebigfishexperience.org.uk/sources/ajax/venue-json.php?location=peterborough" rel="nofollow">see this one</a>.</p>
  
  <p>As you can see the JSON does not cater for the sections but I am yet to implement this, so i would need to know beforehand so I do not have to amend much code later on.</p>
  
  <p><strong>OK - I am using Stig JSON parser.</strong></p>
  
  <p>Here is my ListVenuesView.h (connected to table view)</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "SBJson.h"
  
  @interface ListVenuesView : UITableViewController &lt;UITableViewDelegate, UITableViewDataSource&gt; {
      IBOutlet UITableView *venueList;
      NSMutableDictionary *jsonArray;
  }
  
  @property (nonatomic, retain) IBOutlet UITableView *venueList;
  @property (nonatomic, retain) NSMutableDictionary *jsonArray;
  
  @end
  </code></pre>
  
  <p>jsonArray is used to store the JSON data and eventually the proper array.</p>
  
  <p>And here is my ListVenuesView.m (key areas in question)</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      NSLog(@"Table View Loaded");
  
      // Uncomment the following line to preserve selection between presentations.
      // self.clearsSelectionOnViewWillAppear = NO;
  
      // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
      // self.navigationItem.rightBarButtonItem = self.editButtonItem;
  
      // This is where we load the JSON data
  
      NSURL *jsonURL = [NSURL URLWithString:@"http://www.thebigfishexperience.org.uk/sources/ajax/venue-json.php?location=peterborough"];
  
      NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL];
      NSLog(@"%@", jsonData);
  
      // Convert jsonData to array
      self.jsonArray = [jsonData JSONValue];
      NSLog(@"%@", jsonArray);
  
      NSLog(@"count is: %i", [self.jsonArray count]);
  
      // Release NSString and NSURL
      [jsonURL release];
      [jsonData release];
  
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      // Return the number of rows in the section.
      return [self.jsonArray count];
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
      }
  
      NSMutableDictionary *dict = [self.jsonArray objectAtIndex: indexPath.row];
  
      cell.textLabel.font = [UIFont fontWithName:@"Arial" size:15.0];
  
      cell.textLabel.text = [dict objectForKey:@"venueName"];
      cell.detailTextLabel.text = [dict objectForKey:@"venueCordDist"];
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  
      // Configure the cell...
  
      return cell;
  </code></pre>
  
  <p>Also how can I use the data in the cells to go to another subview of the nav controller which gives me a back button and displays the info from the JSON string just for that particular cell that has been tapped.</p>
  
  <p>I think this has something to do with it? Not sure though as this is my first app i am building! So probably expect more pleas of assistance - ha ! ;)</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      // Navigation logic may go here. Create and push another view controller.
      /*
       DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"Nib name" bundle:nil];
       // ...
       // Pass the selected object to the new view controller.
       [self.navigationController pushViewController:detailViewController animated:YES];
       [detailViewController release];
       */
  }
  </code></pre>