Help please 🙂
I have set up a mutable array as follows
- (void)viewDidLoad {
[super viewDidLoad];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"TopImage" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"topImage" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptor release];
[sortDescriptors release];
NSError *error = nil;
NSMutableArray *mutableFetchResultsT = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResultsT == nil) {
}
[self setTopImageArray:mutableFetchResultsT];}
And im trying to populate a UIImageView using :
- (void)showPhoto:(NSInteger)numberToAdd
{
[topIV setImage:[topImageArray objectAtIndex:currentPI + numberToAdd]];
}
currentPI is an integer marking current image in index and number to add is set here:
- (IBAction)nextTouch
{
[self showPhoto:-1];
}
This will skip to next image (thankyou to @XenElement for this insight).
No images load in UIImageView at all.
MutableArray is getting populated through imagePickerController.
The following is my dedicated Image>Data Data>Image converter class
@implementation Image2Data
+ (BOOL)allowsReverseTransformation {
return YES;
}
+ (Class)transformedValueClass {
return [NSData class];
}
- (id)transformedValue:(id)value {
return UIImagePNGRepresentation(value);
}
- (id)reverseTransformedValue:(id)value {
return [[[UIImage alloc] initWithData:value] autorelease];
}
@end
This is initialized in my managed objects class with:
+ (void)initialize {
if (self == [Images class]) {
Image2Data *transformer = [[Image2Data alloc] init];
[NSValueTransformer setValueTransformer:transformer forName:@"Image2Data"];
}
}
Thank you in advance for any suggestions
DetartrateD
I had originally put:
[topImageArray insertObject:imageS atIndex:0];
corrected to:
[topImageArray insertObject:imageS.topImage atIndex:0];
:)))) big laugh, I was pointing to my entity not its attribute ahh well, lesson learned!
It is unlikely that you are storing the image as a
UIImageobject. You must be converting it into aNSDataobject before storing it. You must convert it back to aUIImageobject usinginitWithData:prior to setting it to theUIImageViewinstance.