0

I am making an app which has an user input form in it. Now using storyboard, when I set the ViewController which has the form on it as it's initial View Controller and setting the rootViewController in the APp Delegate, I get to save the data with out worries.

When I want to launch the app into another ViewController and have a button link to the input form, I can fill in the form, but when I press save, it tells me that it cannot find the Entity in question.

The Code below is from the appDelegate.m file and the moment it set to the VC that handles the data input. I want to set it so that the ViewController, which is currently commented out becomes the root and then when I save the button on the AddDataVC that it can find the Entity.

I am pretty certain my CoreData code is fine as it is able to save data, but it only crashes when the input form is not the initial ViewController.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

AddDataVC *addDataVC = (AddDataVC *)self.window.rootViewController;
addDataVC.managedObjectContext = self.managedObjectContext;
//ViewController *controller = (ViewController *)self.window.rootViewController;
//controller.managedObjectContext = self.managedObjectContext;
return YES;
}

Thanks in advance:-)

--EDIT--

Below I have pasted the error from the console:

2012-05-17 23:46:37.288 SW_Vault[26604:15203] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Product''

--EDIT 2--

Ok so what I am trying to explain is this. When I use a template like the utility app it allows me to create the Entity and set up a textField and a Save Button and it saves the data just fine. The image is off the storyboard. Notice how there is only 1 VC and it is the initial View:

enter image description here

But when I have another VC as the initial View Controller then it comes up with the error that the entity cannot be found. Which is the error I described above.

enter image description here

Now the code for the Entry View has not changed, but if you look at the first -(BOOL) I posted in this question I can choose between 2 rootViewControllers, I just have to comment one out to use the other.

Now in the second image, if I make the the second VC in that board the initial VC then I do not have a problem, it is only when I get there via a Segue.

I hope that makes more sense:-)

jwknz
  • 6,598
  • 16
  • 72
  • 115

2 Answers2

0

The error means that you're probably not loading the Managed Object Model that defines Product.

To avoid this, somewhere in your code (maybe the AppDelegate) you need to set the Core Data stack.

For further info I suggest to read this stackoverflow post.

Community
  • 1
  • 1
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
  • No sorry, I have checked all that and also opened a new project based on a utility template that has coredata as a base - that template assumes that the textfields, or whatever the input is, are going to be on the initial screen. I am wanting them to appear on another one. – jwknz May 17 '12 at 12:01
  • @jwk82 Sorry but I don't understand your question. Could you provide more details? What do you mean with *I am wanting them to appear on another one*? Then, what about the *window*? Do you create it with a xib file? Thanks. – Lorenzo B May 17 '12 at 12:56
  • I have updated the question with a few images to explain what my problem is - I hope this makes more sense. PS Sorry for the big wait in the reply, needed a nights sleep:-) – jwknz May 17 '12 at 20:29
0

Alright I have the answer to the question:-)

I had to setup a Segue to get it to work. I asked the question here and got this answer:-)

Ray Wenderlich Forums

jwknz
  • 6,598
  • 16
  • 72
  • 115