Instead of having array for each state you should put data together because they are related.
List of States:
_listOfStates =
@{
@"Alabama":@[
@{@"area":@"albama area 1", @"description":@"Alabama specs 1"},
@{@"area":@"albama area 2", @"description":@"Alabama specs 2"},
@{@"area":@"albama area 3", @"description":@"Alabama specs 3"},
],
@"Georgia":@[
@{@"area":@"Georgia area 1", @"description":@"Georgia specs 1"},
@{@"area":@"Georgia area 2", @"description":@"Georgia specs 2"},
@{@"area":@"Georgia area 3", @"description":@"Georgia specs 3"}
],
@"Tennessee":@[
@{@"area":@"Tennessee area 1", @"description":@"Tennessee specs 1"},
@{@"area":@"Tennessee area 2", @"description":@"Tennessee specs 2"},
@{@"area":@"Tennessee area 3", @"description":@"Tennessee specs 3"}
]
};
State Array:
self.state = [_listOfStates objectForKey:_stateName];
numberOfRowsInSection
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.state count];
}
cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"Animal2Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.textLabel.text = [[self.state objectAtIndex:indexPath.row] objectForkey:@"area"];
return cell;
}
didSelectRowAtIndexPath
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self performSegueWithIdentifier:@"detailSegue" sender:sender];
}
prepareForSegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"detailSegue"])
{
//get the specs
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *description = [[self.state objectAtIndex:indexPath.row] objectForkey:@"description"];
//set the specs
DetailViewController *detailVC= (DetailViewController *)segue.destinationViewController;
detailVC.description= description;
}
}