0
votes

I have two viewcontrollers that are both bundled with navigationcontrollers. Im trying to send an object from one viewcontroller to the other. I use the code below in the didselectrow of the table:

UIViewController *serviceTable = [self.storyboard instantiateViewControllerWithIdentifier:@"navigationServiceNews"];

    ((TableServiceNews*)serviceTable).service_ID = [ServiceID objectAtIndex:indexPath.row];

    [self.slidingViewController anchorTopViewOffScreenTo:ECRight
        animations:nil onComplete:^{
        CGRect frame = self.slidingViewController.topViewController.view.frame;
        self.slidingViewController.topViewController = serviceTable;
        self.slidingViewController.topViewController.view.frame = frame;
        [self.slidingViewController resetTopView];
    }];

The identifier that im using (navigationServiceNews) points to the navigationcontroller that is bundled with the destination viewcontroller.

While using this identifier, the app crashes because obviously instantiateViewControllerWithIdentifier returns a veiwcontroller not a navigationcontroller.

When i change the identifier to the ID of the destination viewcontroller,every works fine but i lose the navigationBar on the header which is very important to my project(it is the reason i decided to bundle the viewcontrollers with navigationcontroller).

1

1 Answers

0
votes

If "navigationServiceNews" is the identifier you assigned to the navigation controller, then instantiateViewControllerWithIdentifier: will instantiate a navigation controller not a UIViewController, so that's not your problem. You problem is on the next line -- I assume that serviceID is a property on TableServiceNews not the navigation controller, so you need to get ahold of that controller using topViewController.

    UINavigationController *serviceTableNav = [self.storyboard instantiateViewControllerWithIdentifier:@"navigationServiceNews"];
    TableServiceNews *serviceTable = serviceTableNav.topViewController;

    serviceTable.service_ID = [ServiceID objectAtIndex:indexPath.row];

    [self.slidingViewController anchorTopViewOffScreenTo:ECRight
            animations:nil onComplete:^{
            CGRect frame = self.slidingViewController.topViewController.view.frame;
            self.slidingViewController.topViewController = serviceTable;
            self.slidingViewController.topViewController.view.frame = frame;
            [self.slidingViewController resetTopView];
    }];