title: Dynamic titles for sections in UITableView
body: <p>I want to make a tableview containing our stores - sectioned by city. </p>
  
  <p>The data for the tableview is collected thru my webapp's API in a json string which I parse to a NSDictionary using the opensource Objective-c JSON framework.</p>
  
  <p>The response looks a bit like this:</p>
  
  <pre><code>    {
  city = "Amsterdam";
  code = erbur;
  title = "Shop Lorem";
  },
  {
  city = "Amsterdam";
  code = kadap;
  title = "Shop Ipsum";
  },
  {
  city = "Rotterdam";
  code = elaml;
  title = "Shop Dolor";
  },
  {
  city = "Delft";
  code = lamla;
  title = "Shop Sit";
  },
  {
  city = "Rotterdam";
  code = koppa;
  title = "Shop Amet";
  },
  </code></pre>
  
  <p>My initial plan was to create one array per city, store those arrays in a dictionary and than, when naming the sections with <code>titleForHeaderInSection:</code> do something like this:</p>
  
  <pre><code>if (section == 0) {
      return @"Amsterdam"; }
  else if (section == 1)  {
      return @"Roteterdam";
  } Etc..
  </code></pre>
  
  <p>Here's the problem: We are expanding quite rapidly and I don't want to update my app everytime we open a shop in a new city. So I can't hardcode the arrays for the cities. </p>
  
  <p>What would be the right way to make sure that new stores in new cities are displayed in the table view within the right city?</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT</strong>
  Here's my code:</p>
  
  <pre><code> - (void)getLocData
      {
  
          SBJSON *parser = [[SBJSON alloc] init];
  
          NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://foo.bar/locaties/lijst"]];
          [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
  
          NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  
          NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
  
          NSArray *statuses = [parser objectWithString:json_string error:nil];
  
          //the abive works
  
          [statusesArray release];
          statusesArray = statuses;
  
  
          NSArray *cityNames = [statuses valueForKey:@"code"];
  
  
      [locationCodes release];
      locationCodes = cityNames;
  
  
      - (void)viewDidLoad {
          [super viewDidLoad];
  
      [self getLocData];
  
          //titel
          self.title = NSLocalizedString(@"Locaties", @"Locaties - Steden");
  
  
  
      }
      - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  
          return [locationCodes count];
  
      }
  
  
      - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  
          return 1;
  
      }
  
      - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  
          return [locationCodes objectAtIndex:section];
  
      }
  
  
      // Customize the appearance of table view cells.
      - (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];
          }
  
          // Configure the cell...
  
  
  
  
          NSString *cityName = [locationCodes objectAtIndex:[indexPath section]];
          NSPredicate *predicate = [NSPredicate predicateWithFormat:@"code like %@", cityName];
  
          NSArray *filteredShops = [statusesArray filteredArrayUsingPredicate:predicate];
          NSDictionary *currentShop = [filteredShops objectAtIndex:[indexPath row]];
  
          NSString *cellTitle = [currentShop objectForKey:@"title"];
  
          cell.textlabel.text = cellTitle;
          return cell;
  
      }
  </code></pre>