My question is ay when the user presses "Tennessee Hops", when they press that I want to it to push to a detail view listing the specs of that area... So from the opening of the app it would go Tennessee(RootTable) -> Tennessee Hops(SecondTable) -> Specs(DetailView). Can someone lead me in the right direction as to how to get this to function correctly?
Thanks!
RootTableViewController.h
#import <UIKit/UIKit.h>
@interface RootTableViewController : UITableViewController
@end
RootTableViewController.m
#import "RootTableViewController.h"
#import "SecondTableViewController.h"
@interface RootTableViewController ()
@end
@implementation RootTableViewController
{
NSMutableArray *states;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
states = [NSMutableArray arrayWithObjects:@"Alabama", @"Georgia", @"Tennessee", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [states count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"StatesCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [states objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"showArrayDetail"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
SecondTableViewController *destViewController = segue.destinationViewController;
destViewController.stateName = [states objectAtIndex:indexPath.row];
destViewController.title = destViewController.stateName;
}
}
@end
SecondTableViewController.h
#import <UIKit/UIKit.h>
@interface SecondTableViewController : UITableViewController
@property (nonatomic, strong) NSString *stateName;
@property (nonatomic, strong) NSString *areaName;
@end
SecondTableViewController.m
#import "SecondTableViewController.h"
@interface SecondTableViewController ()
@end
@implementation SecondTableViewController
{
NSMutableArray *alabama;
NSMutableArray *georgia;
NSMutableArray *tennessee;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
alabama = [NSMutableArray arrayWithObjects:@"Moss Rock Preserve Boulder Fields", nil];
georgia = [NSMutableArray arrayWithObjects:@"Georgia Pines", nil];
tennessee = [NSMutableArray arrayWithObjects:@"Tennessee Hops", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if([_stateName isEqualToString:@"Alabama"])
{
return [alabama count];
}
else if([_stateName isEqualToString:@"Georgia"])
{
return [georgia count];
}
else if([_stateName isEqualToString:@"Tennessee"])
{
return [tennessee count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"Animal2Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if([_stateName isEqualToString:@"Alabama"])
{
cell.textLabel.text = [alabama objectAtIndex:indexPath.row];
}
else if([_stateName isEqualToString:@"Georgia"])
{
cell.textLabel.text = [georgia objectAtIndex:indexPath.row];
}
else if([_stateName isEqualToString:@"Tennessee"])
{
cell.textLabel.text = [tennessee objectAtIndex:indexPath.row];
}
return cell;
}