Reputation: 1533
Im having a ViewController in a storyboard that presents images, i want to have "next" and "prev" buttons to move through instances(10 viewControllers) of the same class that contains different images. The "first" instance is part of a storyboard, i programmed manually all the images that are subview of a scrollbar. Now the question is how to add properly manual ViewControllers
If so , is there a way to know which instance of the array i am ? so i would know when to "stop" and not display "next" button or "prev" button
VCDecorations *page1 = [self.storyboard instantiateViewControllerWithIdentifier:@"VCDecorations"];
VCDecorations *page2 = [self.storyboard instantiateViewControllerWithIdentifier:@"VCDecorations"];
VCDecorations *page3 = [self.storyboard instantiateViewControllerWithIdentifier:@"VCDecorations"];
DecoViewControllers = [[NSArray alloc]initWithObjects:page1,page2,page3, nil];
Is there away to know if i"m currently in "page1" or "page2" ?
Thank you.
Upvotes: 0
Views: 65
Reputation: 29
Try this Example:
self.imageArray = [NSArray arrayWithObjects:@"image1.png",@"image2.png"],@"image3.png"],@"image4.png"],@"image5.png"],@"image6.png"],nil];
self.currentIndex = 0;
-(IBAction)nextImageClicked:(id)sender{
if (self.currentIndex < self.imageArray.count-1) {
self.currentIndex++;
NSString *imageName = [NSString stringWithFormat:@"%@",[self.imageArray objectAtIndex:self.currentIndex]];
UIImage * image = [UIImage imageNamed:imageName];
self.imageView.image = image;
}
}
-(IBAction)prevImageClicked:(id)sender{
if (self.currentIndex > 0) {
self.currentIndex--;
NSString *imageName = [NSString stringWithFormat:@"%@",[self.imageArray objectAtIndex:self.currentIndex]];
UIImage * image = [UIImage imageNamed:imageName];
self.imageView.image = image;
}
}
Upvotes: 0
Reputation: 506
Instead of using different viewControllers use single viewController and add all images in a an array and when next or Previous button is tapped change the image in imageView according to your array.
Upvotes: 2