10/26/2014 - 11:07 PM


#import "CPRAppDelegate.h"
#import "CPRPersistentStack.h"
#import <RestKit/RestKit.h>

#import "CPRNavigationController.h" // detail view controller

// tab bar, third item (CPRProductViewController *) 
// I want to call a segue from this controller's tableView delegate: tableView:didSelectRowAtIndexPath: method
// This works for replace, however once i replace the detail view the reference is lost and the next selected row crashes
// What I want to do is push a view controller on to this controller, but I get the error
// 2014-10-27 09:03:41.109 comprint[29758:1190187] Product Controller set from AppDelegate: <CPRProductsViewController: 0x7beb4ba0>
// 2014-10-27 09:03:41.109 comprint[29758:1190187] Navigation Controller set from AppDelegate: <CPRNavigationController: 0x7bebabe0>
// 2014-10-27 09:03:47.114 comprint[29758:1190187] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'PushJobForm'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
#import "CPRProductsViewController.h" 

@implementation CPRAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    UISplitViewController *splitViewController = (UISplitViewController *) self.window.rootViewController;
    UITabBarController *tabBarController = [splitViewController.viewControllers objectAtIndex:0];
    __unused CPRProductsViewController *leftViewController = (CPRProductsViewController *)[tabBarController.viewControllers objectAtIndex:2];
    __unused CPRNavigationController *rightViewController = [splitViewController.viewControllers objectAtIndex:1];

    [self setupCoreData];
    leftViewController.navController = rightViewController; // Pointer to the navcontroller for product view controller
    NSLog(@"Product Controller from AppDelegate: %@", leftViewController);
    NSLog(@"Nav Controller from AppDelegate: %@", rightViewController);
    return YES;


// ...
// Im probably useing the method performSegueWithIdentifier:sender: wrongly 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    products *product = [self.products objectAtIndex:indexPath.row];
    [self.navController performSegueWithIdentifier:@"PushJobForm" sender:product];
// ...
#import "CPRNavigationController.h"
#import "CPRJobFormController.h"

@implementation CPRNavigationController

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    CPRJobFormController *controller = [segue destinationViewController];
    controller.product = sender;