Search code examples
ios6uiscrollviewpaginationsplash-screen

ScrollView Page Indicators not appearing


I am new to IOS so please help me guide on this question.

I am working on three views which open three different images connected by scroll view and pagination. I am using XIB to get the pagination logic and scroll view.

I am facing two issues:

  1. I am not able to get the page indicator to appear on the screen with different views

  2. I am finding it difficult to move to the next view controller once I reach the third view.

I am following this tutorial by Ray Wanderlich. I am struck on where to add the code to move to next view controller once user tries to swipe to next page on reaching the last page.

My code is like this:

- (void)viewDidLoad {
[super viewDidLoad];


   self.navigationController.navigationBarHidden =YES;
// Set up the image we want to scroll & zoom and add it to the scroll view
self.pageImages = [NSArray arrayWithObjects:
                   [UIImage imageNamed:@"IMAGE1.png"],
                   [UIImage imageNamed:@"IMAGE2.png"],
                   [UIImage imageNamed:@"IMAGE3.png"],
                  // [UIImage imageNamed:@"photo4.png"],
                  // [UIImage imageNamed:@"photo5.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)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;

NSLog(@"One %d",page);

if (page == 2) {

    page = 3;

    if(page == 3){
         NSLog(@"Working");

        SignInViewController *view = [[SignInViewController alloc]initWithNibName:@"SignInViewController" bundle:nil];
        [self.navigationController pushViewController:view animated:NO];
        [view release];
        view=nil;
    }

}

// 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];
}


    // Load pages in our range
for (NSInteger i=firstPage; i<=lastPage; i++) {
    [self loadPage:i];


}


    // Purge anything after the last page
for (NSInteger i=lastPage+1; i<self.pageImages.count; i++) {
    [self purgePage:i];

}

}

I tried to add the lines of my view controller as :

SignInViewController *view = [[SignInViewController alloc]initWithNibName:@"SignInViewController" bundle:nil];
            [self.navigationController pushViewController:view animated:NO];
            [view release];
            view=nil; 

But this makes the third image disappear and takes the user directly to my SignInView controller page once the user tries to swipes to the third image from the second image.

What should I do to make the user see the third image then detect the swipe and move to the next view controller with animation. I tried with swipe animation and detection but it did not work for me. Where do I need to code and how please help !!.


Solution

  • I think it might be late to reply but may be you still might be struck and need help then here is the solution to your second issue:

    Answer to part 2.->

    try and add this code

    if (page == 2) {
    
        page = 3;
    
        if(page == 3){
    
            NSLog(@"content ofset--  %f",self.scrollView.contentOffset.x);
    
            if (self.scrollView.contentOffset.x>=700)
            {
                SignIn2ViewController *view = [[SignIn2ViewController alloc]initWithNibName:@"SignIn2ViewController" bundle:nil];
                [self.navigationController pushViewController:view animated:NO];
                [view release];
                view=nil;
            }
    
        }
    }
    

    You can check for the offset's value to according to your need. may be this works for u.

    and answer to part 1. -->try to read Ray Wanderlich tutorial again and check the settings of XIB you might have skipped some information to be added on outlets or page indicators.

    Hope it works for you.