Note that there are some explanatory texts on larger screens.

plurals
  1. POUIButton and action for "next' and previous image
    text
    copied!<p>So, pretty new to iPhone dev and learning all the time. I know what I want but dont quite know where to start. I have really only dealt with tableView apps before this project so my practical knowledge of imageView's and custom actions is very much lacking!</p> <p>I want to have a UIImageView loaded with an image (using an array populated by a fetchedResultsController as images will be stored in a CoreData DB ). </p> <p>I want an UIButton with action "next" and UIButton with action "previous" which will control the previously mentioned imageViews' displayed image.</p> <p>Thus far I have the DB mapped and interface design but am failing to find this answer to these points (I am sure it will be fairly straight forward to those who know).</p> <p>Any advise or example code would be greatly appreciated. </p> <p>DetartrateD</p> <p>@shawnwall code snippet from below...</p> <pre><code>-(IBAction)nextImage { index++; int imageCount=31; if (index&lt;=imageCount) { NSString* imageName=[NSString stringWithFormat:@"img%i.jpg", index]; [picture setImage: [UIImage imageNamed: imageName]]; } } </code></pre> <p>Mutatable array seeded in viewDidLoad:</p> <pre><code>NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Images" 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:&amp;error]mutableCopy]; if (mutableFetchResultsT == nil) { } [self setTopImageArray:mutableFetchResultsT]; NSLog(@"%i" , [topImageArray count]); </code></pre> <p>Image being added to array here:</p> <pre><code>Images *imageS = (Images *)[NSEntityDescription insertNewObjectForEntityForName:@"Images" inManagedObjectContext:managedObjectContext]; imageS.topImage = selectedImage; [topImageArray insertObject:imageS.topImage atIndex:0]; NSLog(@"%i" , [topImageArray count]); </code></pre> <p>... ...</p> <p>Same method but after I have created a thumbnail i call:</p> <pre><code>[self updateTopIV]; </code></pre> <p>Which is :</p> <pre><code>-(void)updateTopIV { topIV.image = [topImageArray objectAtIndex:0]; } </code></pre> <p>I then have the 2 action buttons (next/previous):</p> <pre><code>- (IBAction)nextTouch { [self showPhoto:1]; } - (IBAction)previousTouch { [self showPhoto:-1]; } - (void)showPhoto:(NSInteger)numberToAdd { topIV.image = [topImageArray objectAtIndex:currentPhotoIndex + numberToAdd]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload