Reputation: 767
App is crashing with error _NSCFConstantString CGImage]: unrecognized selector sent to instance
when trying app with this code to save image to photo album
int currentimage = _imageScrollView.contentOffset.y / [pictures count];
UIImage *imageToShow = [pictures objectAtIndex:currentimage];
UIImageWriteToSavedPhotosAlbum(imageToShow, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);
Upvotes: 1
Views: 873
Reputation: 8538
By the information that you gave in the comments, you are using an UIImage reference ("imageToShow") that is pointing to a NSString (element from the array), and that is why when imageToShow receive the CGImage selector, crashes.
To solve this problem, you have to put UIImage references to UIImage objects in the array.
UIImage *image0 = [UIImage imageWithContentsOfFile:"image0FullPath.png"];
UIImage *image1 = [UIImage imageWithContentsOfFile:"image1FullPath.png"];
pictures = [[NSArray alloc] initWithObjects:image0, image1, nil];
If the images are in the mainbundle, you can use imageNamed instead of imageWithContentsOfFile. imageNamed receive as input only the name of the file, and search for it inside the mainbundle. imageWithContentsOfFile needs the full path.
Good Luck!
Upvotes: 2