dear developer i want make an image from an offscreen view.
when i start my app the first view is the RootViewController and everthing
works fine.
when i go to an other view and make this.
RootViewController *root = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
UIImage *screenShot = [self imageWithView: root.tableView];
(UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, [[UIScreen mainScreen] scale]);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
The app crash in the “imageWithView:(UIView *)view” function at the line
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
the log says
Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘+entityForName: could not locate an NSManagedObjectModel for entity name ‘ListItem”
and this happen in the rootviewcontroller on the line
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ListItem" inManagedObjectContext:self.managedObjectContext];
somebody an idea?
As Rog said there is probably no context. Here is the code that create the one correctly:
And in @interface you have to declare 3 ivars and properties: