Next button image array xcode - ios

I'm trying to code an app in Xcode 4, with storyboarding.
My project is something like this:
1 table view controller
1 detail view controller with 4 buttons,
and say 6 images( 1-1.jpg/1-2.jpg/1-3.jpg, and 2-1.jpg/2-2.jpg/2-3.jpg.
I have got my app to show the images(1-1.jpg and 2-1.jpg) in the array when clicking the cells.
And this is my code:
// TableViewController.m:
#synthesize myTitle = _myTitle;
#synthesize myScene = _myScene;
#synthesize myImages = _myImages;
- (void)viewDidLoad
{
[super viewDidLoad];
self.myTitle = [[NSArray alloc] initWithObjects:#"Chicken", #"Flower", nil];
self.myScene = [[NSArray alloc] initWithObjects:#"1", #"2", nil];
self.myImages = [[NSArray alloc] initWithObjects:#"1-1.jpg", #"2-1.jpg", nil];
}
// DetailViewController.m
#synthesize titleLabel = _titleLabel;
#synthesize sceneLabel = _sceneLabel;
#synthesize imageView = _imageView;
#synthesize myDetailModel = _myDetailModel;
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = self.titleLabel.text = [self.myDetailModel objectAtIndex:0];
self.sceneLabel.text = [self.myDetailModel objectAtIndex:1];
self.imageView.image = [UIImage imageNamed:
[self.myDetailModel objectAtIndex:2]];
I want my DetailView page to show the next or previous image(1-2.jpg/1-3.jpg... / 2-2.jpg, 2-3.jpg...) each time I press next or previous (black)button,
and to show next or previous scene(chicken scene and flower scene) when I press another (green)buttons,
like https://dl.dropboxusercontent.com/u/7493131/q3.jpg
I don't know how to array 1-2.jpg, 1-3.jpg, 2-2.jpg and 2-3.jpg and what to do with them.
I am so new that I would like some example code to help please to study how it works,
and how I can implement similar within my app. Thank you.

-(IBAction)rightClick{
if (imageArrayObj.count > 0) {
currentIndex++;
if (currentIndex > imageArrayObj.count - 1) {
currentIndex = 0;
}
imageViewObj.image = [imageArrayObj objectAtIndex:currentIndex];
}
}
It's working properly ..... Use this and currentIndex is integer declare " int currentIndex;" and assign value in view did load "currentIndex = 0;"

You need to create an instance int variable idx to keep track of which image you are handling and assign two IBActions to those buttons :
// This is for your fighter case
- (IBAction)presentPreviousImage:(id)sender {
idx --;
if (idx == 2) {
self.imageView.image = [UIImage imageNamed:#"1-3.jpg"];
} else if (idx == 1) {
self.imageView.image = [UIImage imageNamed:#"1-2.jpg"];
} else if (idx == 0) {
self.imageView.image = [UIImage imageNamed:#"1-1.jpg"];
idx = 2;
}
}
- (IBAction)presentNextImage:(id)sender {
idx ++;
if (idx == 0) {
self.imageView.image = [UIImage imageNamed:#"1-2.jpg"];
} else if (idx == 1) {
self.imageView.image = [UIImage imageNamed:#"1-3.jpg"];
} else if (idx == 2) {
self.imageView.image = [UIImage imageNamed:#"1-1.jpg"];
idx = 0;
}
}

Related

iOS How can I dynamic change the PageControl color when change the page?

I have 3 page - A ViewController, B ViewController and C ViewController.
And A PageViewController control there horizontal scroll.
PagesViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.aVC = [self.storyboard
instantiateViewControllerWithIdentifier:#"AViewController"];
self.bVC = [self.storyboard
instantiateViewControllerWithIdentifier:#"BViewController"];
self.cVC = [self.storyboard
instantiateViewControllerWithIdentifier:#"CViewController"];
self.delegate = self;
self.dataSource = self;
self.allViewControllers = #[self.aVC,self.bVC
,self.cVC];
[self setViewControllers:#[self.aVC]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
_pageControl = [UIPageControl appearance];
}
I want to change the _pageControl color when I scroll to A VC , B VC and C VC.
So I put the code in
-(NSInteger)presentationIndexForPageViewController:
(UIPageViewController *)pageViewController
{
NSLog(#"%#",pageViewController.viewControllers[0]);
for( int i = 0 ; i< self.allViewControllers.count ; i++ )
{
if( pageViewController.viewControllers[0] == self.allViewControllers[i])
{
if( i ==0 )
{
_pageControl.backgroundColor = [UIColor greenColor];
}
else if( i ==1)
{
_pageControl.backgroundColor = [UIColor redColor];
}
else
{
_pageControl.backgroundColor = [UIColor clearColor];
}
NSLog(#"return index:%d", i);
return i;
}
}
return 0;
}
But the page control was not change the color.
I try to put below the code in the viewDidLoad, it will change color at all the view controller.
_pageControl.backgroundColor = [UIColor redColor];
But now I want to change the pageControl color when I scroll to different UIViewController.
How can I do? or How can I refresh the pageControl color?
Because now the color always black.
I offer others delegate method about the PageViewController:
-(UIViewController*) pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [self.allViewControllers indexOfObject:viewController];
if( currentIndex == 0 )
{
return nil;
}
currentIndex--;
return [self.allViewControllers objectAtIndex:currentIndex];
}
-(UIViewController *) pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [self.allViewControllers indexOfObject:viewController];
NSLog(#"after currentIndex:%ld",currentIndex);
currentIndex++;
if( currentIndex == [self.allViewControllers count])
{
return nil;
}
return [self.allViewControllers objectAtIndex:currentIndex];
}
-(NSInteger)presentationCountForPageViewController:
(UIPageViewController *)pageViewController
{
return self.allViewControllers.count;
}
In your viewDidLoad: method,
instead of:
_pageControl = [UIPageControl appearance];
use:
NSArray *subviews = self.view.subviews;
_pageControl = nil;
for (int i=0; i<[subviews count]; i++) {
if ([[subviews objectAtIndex:i] isKindOfClass:[UIPageControl class]]) {
_pageControl = (UIPageControl *)[subviews objectAtIndex:i];
}
}
=====
EDIT:
For your specific project, you're not getting the _pageControl (it's returning nil) because the Storyboard has not completed instantiating your view controller in the viewDidLoad. I thought it would need to go in viewDidAppear:animated, but that didn't work either, so I cheated by delaying requesting it for 0.2 milliseconds.
In your viewDidLoad, put this:
[self performSelector:#selector(findPageControl) withObject:nil afterDelay:0.2f];
Then, add this method:
- (void) findPageControl {
NSArray *subviews = self.view.subviews;
_pageControl = nil;
for (int i=0; i<[subviews count]; i++) {
if ([[subviews objectAtIndex:i] isKindOfClass:[UIPageControl class]]) {
_pageControl = (UIPageControl *)[subviews objectAtIndex:i];
}
}
[self changePage:0];
}
In your viewControllerAfterViewController method, I added this right after the NSUInteger currentIndex = line:
[self changePage:currentIndex];
That seems to have made it work. Now, you could add an animation in your changePage method to make the transition seem a little smoother.
Also, when debugging, this is what I did:
I added a breakpoint on the _pageControl = line, so I could check and see what was happening. When I saw it was nil, that told me that it wasn't being set properly. Look in the debug area, and you can see what I printed out ("po") to see what values existed -- and why there was no UIPageControl. If you do the same after the changes I list above, you'll see that this is now found and set.
Here's an example, just with a pageControl in a UIViewController:
#import "ViewController.h"
#interface ViewController () {
UIPageControl *pageControl;
}
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(10, 10, 100, 40)];
pageControl.numberOfPages = 6;
[pageControl addTarget:self action:#selector(changePage:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:pageControl];
}
- (void) changePage:(UIPageControl *)page {
NSInteger currentPage = page.currentPage;
switch (currentPage) {
case 0:
pageControl.backgroundColor = [UIColor redColor];
break;
case 1:
pageControl.backgroundColor = [UIColor greenColor];
break;
case 2:
pageControl.backgroundColor = [UIColor blueColor];
break;
default:
break;
}
}
#end

How to implement a UIPageControl properly?

I have 3 minor issues related to implementing a UIPageControl. I'm not using a UIPageViewController, so I would not like to use that, if possible.
I have implemented a UIPageControl, where, when a user swipes either left or right on the view, it will move to the next "page" and display a different image.
Here is the following code:
ViewController.h:
#property (nonatomic) NSInteger Count;
#property (strong, nonatomic) IBOutlet UIPageControl *Control;
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
#property (strong, nonatomic) IBOutlet UILabel *label;
#property (strong, nonatomic) UISwipeGestureRecognizer *swipeRight, *swipeLeft;
#property (strong, nonatomic) NSArray *array;
ViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.array = #[#"page1", #"page2", #"page3", #"page4"];
self.swipeRight = [ [UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(Right:)];
self.swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:self.swipeRight];
self.swipeLeft = [ [UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(Left:)];
self.swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:self.swipeLeft];
self.Control.numberOfPages = 3;
self.Control.currentPage = 0;
}
-(void)Right: (UITapGestureRecognizer *)sender
{
self.Count = self.Count - 1;
if (self.Count > 3)
{
self.Count = 1;
}
else if (self.Count < 1)
{
self.Count = 3;
}
if (self.Count == 1)
{
self.Control.currentPage = 0;
self.imageView.image = [UIImage imageNamed:[self.array objectAtIndex:self.Control.currentPage]];
// self.label.text = #"this is page 1";
}
else if (self.Count == 2)
{
self.Control.currentPage = 1;
self.imageView.image = [UIImage imageNamed:[self.array objectAtIndex:self.Control.currentPage]];
// self.label.text = #"this is page 2";
}
else if (self.Count == 3)
{
self.Control.currentPage = 2;
self.imageView.image = [UIImage imageNamed:[self.array objectAtIndex:self.Control.currentPage]];
// self.label.text = #"this is page 3";
}
}
-(void)Left: (UITapGestureRecognizer *)sender
{
self.Count = self.Count + 1;
if (self.Count > 3)
{
self.Count = 1;
}
else if (self.Count < 1)
{
self.Count = 3;
}
if (self.Count == 1)
{
self.Control.currentPage = 0;
self.imageView.image = [UIImage imageNamed:[self.array objectAtIndex:self.Control.currentPage]];
//self.label.text = #"this is page 1";
}
else if (self.Count == 2)
{
self.Control.currentPage = 1;
self.imageView.image = [UIImage imageNamed:[self.array objectAtIndex:self.Control.currentPage]];
//self.label.text = #"this is page 2";
}
else if (self.Count == 3)
{
self.Control.currentPage = 2;
self.imageView.image = [UIImage imageNamed:[self.array objectAtIndex:self.Control.currentPage]];
// self.label.text = #"this is page 3";
}
}
The first issue: how do I make the view display the first image at index 0 on launch?
Right now, if you start the app initially, the image is blank on screen even though the page control shows the current view as being highlighted with the little dot. You have to swipe left to get the first image in index 0 to display.
The second issue: how do I add a scroll transition style animation when swiped left or right?
Right now, if you swipe either left or right, the image transition is instant, and you don't see that swiping animation where one image pushes the other image out of the view.
The third issue: how do I make the swipe gesture recognition not be the whole view area, but only be swipeable if you swipe on the upper portion of the view?
Feel free to download the project code as it's just a template that I'm using:
project code
Thanks

Loading multiple View controller in UIPageViewController - Swiping shows blank screen

I am loading multiple UIViewControllers in UIPageViewController with each UIViewController having their own navigation bar. I have implemented all the required data source and delegate methods for UIPageViewController and it showing up correctly.
But when I scroll my view controller horizontally, more often, I see a white blank screen instead of my view controller. Below is my code.
Any clue what could be wrong here.
PS: I tried by removing the IF condition in my viewControllerForRequestID method and returning a new controller every time. This works but then I end up with one view controller showing up twice in pagination.
- (UIViewController *)pageViewController:(UIPageViewController *)iPageViewController viewControllerBeforeViewController:(UIViewController *)iViewController {
[self.pageControl setCurrentPage:self.selectedRequestIndex];
if (self.selectedRequestIndex == 0) {
return nil;
}
NSUInteger aNewSelectedRequestIndex = self.selectedRequestIndex - 1;
NSString *aPreviousRequestID = [self.paginationRequestIDList[aNewSelectedRequestIndex] stringValue];
self.selectedRequestIndex = aNewSelectedRequestIndex;
self.selectedRequestID = aPreviousRequestID;
return [self viewControllerForRequestID:self.selectedRequestID];
}
- (UIViewController *)pageViewController:(UIPageViewController *)iPageViewController viewControllerAfterViewController:(UIViewController *)iViewController {
[self.pageControl setCurrentPage:self.selectedRequestIndex];
if (self.selectedRequestIndex == NSNotFound || self.selectedRequestIndex >= self.paginationRequestIDList.count - 1) {
return nil;
}
NSUInteger aNewSelectedRequestIndex = self.selectedRequestIndex + 1;
NSString *aNextRequestID = self.paginationRequestIDList[aNewSelectedRequestIndex];
self.selectedRequestIndex = aNewSelectedRequestIndex;
self.selectedRequestID = aNextRequestID;
return [self viewControllerForRequestID:self.selectedRequestID];
}
- (MyNavigationViewController *)viewControllerForRequestID:(id)iRequestID {
NSString *aRequestID = iRequestID;
// Safe check to avoid numbers in request ID
if (![iRequestID isKindOfClass:[NSString class]]) {
aRequestID = [iRequestID stringValue];
}
#synchronized (self) {
if ([self.viewControllers containsObjectForKey:iRequestID]) {
MyNavigationViewController *aNavigationController = self.viewControllers[iRequestID];
return aNavigationController;
}
MyDataModel *aRequestData = self.savedRequestData[iRequestID];
MyDataModelController *aRequestInfoController = [[MyDataModelController alloc] initWithRequestData:aRequestData];
aRequestInfoController.delegate = self;
MyNavigationViewController *aNavigationController = [[MyNavigationViewController alloc] initWithRootViewController:aRequestInfoController];
[self.viewControllers setObject:aNavigationController forKey:iRequestID];
return aNavigationController;
}
}

Received memory warning. in gallery section Xcode

I am making a handbook table cell in my app and i have 7 pages which each are the images and I'm using uiscrollview with page control but when i run the app it says Received memory warning.
and then the app freezes and automatically shuts down, what should i do and this is my code.
#interface HS_HandbookViewController ()
#property (nonatomic, strong) NSArray *pageImages;
#property (nonatomic, strong) NSMutableArray *pageViews;
- (void)loadVisiblePages;
- (void)loadPage:(NSInteger)page;
- (void)purgePage:(NSInteger)page;
#end
#implementation HS_HandbookViewController
#synthesize scrollView = _scrollView;
#synthesize pageControl = _pageControl;
#synthesize pageImages = _pageImages;
#synthesize pageViews = _pageViews;
#pragma mark -
- (void)loadVisiblePages {
// First, determine which page is currently visible
CGFloat pageWidth = self.scrollView.frame.size.width;
NSInteger page = (NSInteger)floor((self.scrollView.contentOffset.x * 2.0f + pageWidth) / (pageWidth * 2.0f));
// Update the page control
self.pageControl.currentPage = page;
// Work out which pages we want to load
NSInteger firstPage = page - 1;
NSInteger lastPage = page + 1;
// Purge anything before the first page
for (NSInteger i=0; i<firstPage; i++) {
[self purgePage:i];
}
for (NSInteger i=firstPage; i<=lastPage; i++) {
[self loadPage:i];
}
for (NSInteger i=lastPage+1; i<self.pageImages.count; i++) {
[self purgePage:i];
}
}
- (UIImage *)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
- (void)loadPage:(NSInteger)page {
if (page < 0 || page >= self.pageImages.count) {
// If it's outside the range of what we have to display, then do nothing
return;
}
// Load an individual page, first seeing if we've already loaded it
UIView *pageView = [self.pageViews objectAtIndex:page];
if ((NSNull*)pageView == [NSNull null]) {
CGRect frame = self.scrollView.bounds;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0.0f;
UIImageView *newPageView = [[UIImageView alloc] initWithImage:[self.pageImages objectAtIndex:page]];
newPageView.contentMode = UIViewContentModeScaleAspectFit;
newPageView.frame = frame;
[self.scrollView addSubview:newPageView];
[self.pageViews replaceObjectAtIndex:page withObject:newPageView];
}
}
- (void)purgePage:(NSInteger)page {
if (page < 0 || page >= self.pageImages.count) {
// If it's outside the range of what we have to display, then do nothing
return;
}
// Remove a page from the scroll view and reset the container array
UIView *pageView = [self.pageViews objectAtIndex:page];
if ((NSNull*)pageView != [NSNull null]) {
[pageView removeFromSuperview];
[self.pageViews replaceObjectAtIndex:page withObject:[NSNull null]];
}
}
#pragma mark -
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Student Handbook";
// Set up the image we want to scroll & zoom and add it to the scroll view
self.pageImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"page 1 handbook.png"],
[UIImage imageNamed:#"page 2 handbook.png"],
[UIImage imageNamed:#"page 3 hand book.png"],
[UIImage imageNamed:#"page 4 handbook.png"],
[UIImage imageNamed:#"page 5 handbook.png"],
[UIImage imageNamed:#"page 6 handbook.png"],
[UIImage imageNamed:#"page 7 handbook.png"],
nil];
NSInteger pageCount = self.pageImages.count;
// Set up the page control
self.pageControl.currentPage = 0;
self.pageControl.numberOfPages = pageCount;
// Set up the array to hold the views for each page
self.pageViews = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < pageCount; ++i) {
[self.pageViews addObject:[NSNull null]];
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Set up the content size of the scroll view
CGSize pagesScrollViewSize = self.scrollView.frame.size;
self.scrollView.contentSize = CGSizeMake(pagesScrollViewSize.width * self.pageImages.count, pagesScrollViewSize.height);
// Load the initial set of pages that are on screen
[self loadVisiblePages];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.scrollView = nil;
self.pageControl = nil;
self.pageImages = nil;
self.pageViews = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// Load the pages which are now on screen
[self loadVisiblePages];
}
#end
First of all make sure you have not another apps running ( double tap on home button and flick all running apps to close ). May be images are big and there is not enough memory in your device. If you able to run your app after it try to figure out if you have not memory leaks. Swipe few times and follow your memory.
If you use ARC than assign nil to your vars since you are not going to use them.

NSArray index beyond bounds error

I have created a simple image browser with two buttons to view the next and the previous images.
Here's the code.
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (strong, nonatomic) NSArray *images;
#property (assign, nonatomic) NSInteger imageIndex;
#property (strong, nonatomic) UIBarButtonItem *nextButton;
#property (strong, nonatomic) UIBarButtonItem *prevButon;
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Adding Next and Previous buttons
self.nextButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"next"] style:UIBarButtonItemStylePlain target:self action:#selector(nextButtonPressed)];
self.prevButon = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"previous"] style:UIBarButtonItemStylePlain target:self action:#selector(previousButtonPressed)];
self.navigationItem.rightBarButtonItems = #[self.nextButton, self.prevButon];
// Loading images
self.images = #[
[UIImage imageNamed:#"1"],
[UIImage imageNamed:#"2"],
[UIImage imageNamed:#"3"],
[UIImage imageNamed:#"4"],
[UIImage imageNamed:#"5"],
[UIImage imageNamed:#"6"],
[UIImage imageNamed:#"7"],
[UIImage imageNamed:#"8"],
[UIImage imageNamed:#"9"]
];
self.imageIndex = 0;
self.imageView.image = self.images[self.imageIndex];
}
- (void)nextButtonPressed
{
self.imageIndex++;
self.imageView.image = self.images[self.imageIndex];
}
- (void)previousButtonPressed
{
self.imageIndex--;
self.imageView.image = self.images[self.imageIndex];
}
#end
My problem is say if I tap next button after the last image or previous button when the first image, it'll throw a index beyond bounds error.
How can I stop this from happening?
Thank you.
You have to check whether the index is present in your index.
You can make the verification in your nextButtonPressed and previousButtonPressed methods:
- (void)nextButtonPressed
{
if (imageIndex < ([self.images count] - 1))
{
self.imageIndex++;
self.imageView.image = self.images[self.imageIndex];
}
}
- (void)previousButtonPressed
{
if (imageIndex >= 1)
{
self.imageIndex--;
self.imageView.image = self.images[self.imageIndex];
}
}
For information the NSArray raises an NSRangeException if the index is beyond the end of the array (see the documentation).
You are keeping track of the current image index, which is good, because you can use that to check if there is a next image or a previous by using the image arrays count property.
- (void)nextButtonPressed
{
if ( self.imageIndex < self.images.count - 1) {
self.imageIndex++;
self.imageView.image = self.images[self.imageIndex];
}
}
- (void)previousButtonPressed
{
if ( self.imageIndex > 0 ) {
self.imageIndex--;
self.imageView.image = self.images[self.imageIndex];
}
}
Another alternative is starting over when you reach the last image.
- (void)nextButtonPressed
{
if ( self.imageIndex < self.images.count - 1) {
self.imageIndex++;
} else {
self.imageIndex = 0
}
self.imageView.image = self.images[self.imageIndex];
}
- (void)previousButtonPressed
{
if ( self.imageIndex > 0 ) {
self.imageIndex--;
} else {
self.imageIndex = self.images.count - 1;
}
self.imageView.image = self.images[self.imageIndex];
}
You can use modulus like this - so it wraps around on itself.
This way you never need to disable buttons and it also makes it easier for the user to get from one end of the list to the other more efficiently.
replace the following line
self.imageIndex++;
with
self.imageIndex = (self.imageIndex + 1) % [self.images count];
and where you have the following line
self.imageIndex--;
replace with
self.imageIndex = (self.imageIndex + [self.images count] - 1) % [self.images count];
A good UI habit will be to disable the next (or previous) button once you reach the last image (and of course prevent the overflow in the array):
- (void)nextButtonPressed
{
self.imageIndex++;
self.imageView.image = self.images[self.imageIndex];
[self.previousButton setEnabled:YES];
if (self.imageIndex == [self.images count] - 1) {
[self.nextButton setEnabled:NO];
return ;
}
}
- (void)previousButtonPressed
{
self.imageIndex--;
self.imageView.image = self.images[self.imageIndex];
[self.nextButton setEnabled:YES];
if (self.imageIndex == 0) {
[self.previousButton setEnabled:NO];
return ;
}
}
Since you start with index = 0 you should disable the previous button in viewDidLoad method (as you do not have more previous images until you press next) or do it directly in IB if possible

Resources