I am trying to implement -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
So far this is what I have in my first UITableViewController:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
secondviewcontroller *vc = [[secondviewcontroller alloc]init];
BudgetPlan *tempBudget = [self.budgetElements objectAtIndex:indexPath.row];
vc.budgetPlan = tempBudget;
}
My second view controller has the ff:
// secondviewcontroller.h
@property (strong, nonatomic) BudgetPlan *budgetPlan;
//secondviewcontroller.m
@synthesize budgetPlan = _budgetPlan
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@ was passed with %@",self.budgetPlan.name, self.budgetPlan.amount);
self.budgetName.text = _budgetPlan.name;
self.amountBudgeted.text = [NSString stringWithFormat:@"%.02f", _budgetPlan.amount];
}
Unfortunately, the NSLog shows up as nil. Consequently, UILabels budgetName.text and amountBudgeted.text are also empty.
I’ve set the datasource and delegates to the custom UIViewController which contains the UITableView element (this is not a UITableViewController). It seems like I am passing the object, but it doesn’t seem to be passing…
Where am I going wrong?
Thanks all. The problem seems to be my use of storyboards. This
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPathmethod seems to only work when not using storyboards.I answered it by using Segues instead.