Zafar Ali
Zafar Ali

Reputation: 31

UIScrollView next previous button

next button is only working for 2 images i have 10 images in array after two images it does not move forward previous button is working for all images but next button only work up to one and second image Below are the next Button Code

       - (IBAction)  nextButtonAction {

    if ( self.scrollView.contentOffset.x <= self.scrollView.frame.size.width ) {
    CGRect frame;
    frame.origin.x = self.scrollView.contentOffset.x +self.scrollView.frame.size.width;
    frame.origin.y = 0;
     frame.size = self.scrollView.frame.size;
     [self.scrollView scrollRectToVisible:frame animated:YES];
    pageControlBeingUsed = YES;
       }

     }


 // Here is the previous button code


      -(IBAction)previousButtonAction
    {


    if ( self.scrollView.contentOffset.x >= self.scrollView.frame.size.width ) {
    CGRect frame;
    frame.origin.x = self.scrollView.contentOffset.x -self.scrollView.frame.size.width;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
    [self.scrollView scrollRectToVisible:frame animated:YES];
    pageControlBeingUsed = YES;
   } 
   }

Adding images to the data base

     -(IBAction)addToCollectionButtonAction{




      GeoNewsAppDelegate *appDelegate = (GeoNewsAppDelegate *)[[UIApplication   sharedApplication] delegate];

   // Create a Coffee Object.
    Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:0];

    int pageNumber  = [pageControl currentPage]; 
   NSLog(collectionImage);


   RowTwo*aRowTwo=[appDelegate.articles objectAtIndex:pageNumber];




    NSString*thumb2=aRowTwo.image;

    coffeeObj.thumb = thumb2;
   coffeeObj.path = thumb2; 





         [appDelegate addCoffee:coffeeObj];



      }

Upvotes: 0

Views: 1920

Answers (2)

Sanjeev Rao
Sanjeev Rao

Reputation: 2307

Replace self.scrollView.frame.size.width With self.scrollView.contentSize.width

    - (IBAction)  nextButtonAction {

    if ( self.scrollView.contentOffset.x <= self.scrollView.contentSize.width ) {
    CGRect frame;
    frame.origin.x = self.scrollView.contentOffset.x +self.scrollView.frame.size.width;
    frame.origin.y = 0;
     frame.size = self.scrollView.frame.size;
     [self.scrollView scrollRectToVisible:frame animated:YES];
    pageControlBeingUsed = YES;
       }

     }


 // Here is the previous button code


      -(IBAction)previousButtonAction
    {


    if ( self.scrollView.contentOffset.x >= self.scrollView.frame.size.width ) {
    CGRect frame;
    frame.origin.x = self.scrollView.contentOffset.x -self.scrollView.frame.size.width;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
    [self.scrollView scrollRectToVisible:frame animated:YES];
    pageControlBeingUsed = YES;
   } 
   }

Upvotes: 5

ader
ader

Reputation: 5393

- (IBAction)  nextButtonAction {

    if ( self.scrollView.contentOffset.x < (self.scrollView.frame.size.width*10) ) {
        CGRect frame;
        frame.origin.x = self.scrollView.contentOffset.x +self.scrollView.frame.size.width;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;
        [self.scrollView scrollRectToVisible:frame animated:YES];
        pageControlBeingUsed = YES;
    }

}

Upvotes: 1

Related Questions