0

I've managed to create a tableViewController inside a NavigationController (using the CoreDataTableViewController from Stanford University) with data loaded via Core-Data. The user can check some parameters, set defaults, etc. It works pretty well and the user can also save parameters to the DB and so on.

However this is only a small part of the App I'm building. The App starts with a TabBar controller. The first tab contains a UIViewController and inside this view I want to be able to segue modally the tableViewControllers containing all the core-data stuff.

I believe I've been very careful in setting up the AppDelegate, managedObjectContext and everything else. Obviously, however, I'm missing something because I'm getting the following error when trying to display the modal view :

[UINavigationController setManagedObjectContext:]: unrecognized selector sent to instance... 

I've been searching and this is an indication that somehow the managedObjectContext is not being passed.

The code on the applicationDidFinishLaunching is like this:

  UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;

      RotationVC *rotation=[[tabBarController viewControllers] objectAtIndex:0];
      rotation.managedObjectContext=self.managedObjectContext;

and the prepareForSegue on the view contained inside the first Tab is like this:

if ([segue.identifier isEqualToString:@"SetCameraFromRotationSegue"])
    {

        CameraMakerTVC *cameraMaker = segue.destinationViewController;
        cameraMaker.managedObjectContext=self.managedObjectContext;

    }

it builds Ok and gives no errors nor warnings.

Could anyone give me a hand on this?. I'd really appreciate it!

Thanks in advance!

Marcal
  • 1,371
  • 5
  • 19
  • 37

1 Answers1

0

Probably the issue is here: the "destinationViewController" in the segue is not the CameraMakerTVC (I guess it's the table view controller) but the UINavigationController that contains it. So when you try to do this:

cameraMaker.managedObjectContext=self.managedObjectContext

infact you're trying to call the setter not on a CameraMakerTVC controller but a UINavigationController. You should try to do this:

UINavigationController *nc = segue.destinationViewController;
CameraMakerTVC *cameraMaker = [nc.viewControllers objectAtIndex:0];
cameraMaker.managedObjectContext=self.managedObjectContext;

viggio24
  • 12,316
  • 5
  • 41
  • 34
  • oh, wow! That was exactly it! Thanks a lot! Now that you pointed it out, it makes perfect sense. – Marcal Apr 19 '12 at 11:04