-2

How do I pass between objects from uitableviews to my detail views? I've set up a conditional push, as you can see in my method:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    Budget * tempBudget = [self.budgetPlan.budgets objectAtIndex:indexPath.row];

    NSString *targetViewControllerIdentifier = nil;
    if (tempBudget.hasBeenInitialized != true) {
        targetViewControllerIdentifier = @"budgetInitializerView";
        UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:targetViewControllerIdentifier];
        [self.navigationController pushViewController:vc animated:YES];

        // how do I pass the tempBudget to the pushed view?


    } else {
        targetViewControllerIdentifier = @"budgetDetailsView";
        UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:targetViewControllerIdentifier];
        [self.navigationController pushViewController:vc animated:YES];

        // how do I pass the tempBudget to the pushed view?

    }
}

I'm having trouble with the UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:targetViewControllerIdentifier];

Usually, I just set vc.budget = tempbudget as the answer below suggests, but it does not seem to understand the budget property.

lorenzoid
  • 1,812
  • 10
  • 33
  • 51
  • Can you elaborate on "does not seem to understand the budget property"? Compiler warning? Crash? Nothing displayed on the new view? – jscs Mar 27 '12 at 18:09
  • Nothing is displayed in the new view. It does not seem to be passed. – lorenzoid Mar 27 '12 at 20:52

1 Answers1

1

I would create a BaseViewController that has a @property of type of your object and send your object in that way.

// In your .h
BaseViewController : UIViewController {
}

@property (nonatomic, strong) Budget *budget;

//In your .m
@synthesize budget;

Also, you can move this line out of your if/else statement, since it's the same thing:

vc.budget = tempBudget;
[self.navigationController pushViewController:vc animated:YES];

set your budget property right before you push your view controller

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
El Guapo
  • 5,581
  • 7
  • 54
  • 82