I am trying to push data to a UIViewController from a UITableViewController. When the user presses a climb it is going to push to the UIViewController and display 3 different specs in 3 labels which I have placed on my UIViewController. It is pushing to the detail view, but is not displaying any information. I will post my code:
FourthTableViewController.h
#import <UIKit/UIKit.h>
@interface FourthTableViewController : UITableViewController
@property (nonatomic, strong) NSString *sectionName;
@end
FourthTableViewController.m
#import "FourthTableViewController.h"
#import "DetailViewController.h"
@interface FourthTableViewController ()
@end
@implementation FourthTableViewController
{
NSArray *climbs;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//populating arrays
NSDictionary *dict = @{@"Alabama Section 1":@[@"Alabama Climb 1", @"Alabama Climb 2", @"Alabama
Climb 3"], @"Georgia Section 1": @[@"Georgia Climb 1", @"Georgia Climb 2", @"Georgia Climb 3"],
@"Tennessee Section 1":@[@"Tennessee Climb 1", @"Tennessee Climb 2", @"Tennessee Climb 3"],
@"Colorado Section 1":@[@"Colorado Climb 1", @"Colorado Climb 2", @"Colorado Climb 3"]};
climbs = dict[self.sectionName];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return climbs.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"ClimbCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
//if cell doesn't have anything in it, creates a new one
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = climbs[indexPath.row];
cell.textLabel.font = [UIFont fontWithName:@"Chalkduster" size:17];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"ShowDetails"])
{
DetailViewController *detailViewController = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
int row = [indexPath row];
}
}
DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
{
IBOutlet UILabel *Type;
IBOutlet UILabel *Coordinates;
IBOutlet UILabel *Grade;
}
@property (strong, nonatomic) NSString *detailLabelContents;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
@property (nonatomic, strong) NSString *climbName;
@end
DetailViewController.m
#import "DetailViewController.h"
#import "FourthTableViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
{
NSArray *specs;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//populating arrays
NSDictionary *dict = @{@"Alabama Climb 1":@[@"Alabama Spec 1", @"Alabama Spec 2", @"Alabama Spec
3"], @"Georgia Climb 1": @[@"Georgia Spec 1", @"Georgia Spec 2", @"Georgia Spec 3"], @"Tennessee
Climb 1":@[@"Tennessee Spec 1", @"Tennessee Spec 2", @"Tennessee Spec 3"], @"Colorado Climb
1":@[@"Colorado Spec 1", @"Colorado Spec 2", @"Colorado Spec 3"]};
specs = dict[self.climbName];
self.detailLabel.text = self.detailLabelContents;
if ([_climbName isEqualToString:@"Alabama Climb 1"])
{
Type.text = @"Really Hard";
Coordinates.text = @"10.32145, -83.498621";
Grade.text = @"V10";
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
I know that my issue is in my segue, but am unsure of how to get the information from my if statement to push to the detail view to the 3 labels.
I am not looking for someone to hold my hand and tell me the answer, just some proper guidance and constructive criticism.
Thanks