1. cinek's Avatar
    I'm trying to get pagecontrol to work. Right now I can scroll to the 2nd page, but the background is not changing (im changing the background to make sure it works fine). When I use pageControl to flip through pages, the background changes fine. I think I need to call pageTurning in scrollViewDidScroll but adding [self pageTurningage]; does not work

    this is what I have atm:

    Code:
    static int kNumberOfPages = 2;
    
    #import "AppDelegate.h"
    
    @implementation AppDelegate
    
    @synthesize window = _window;
    @synthesize pageControl, scrollView, viewControllers;
    
    -(IBAction)changePage:(id)sender
    {
        pageControlUsed = YES;
    }
    
    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        pageControlUsed = NO;
    }
    
    -(void)scrollViewDidScroll:(UIScrollView *)sender
    {
        if(pageControlUsed){
            return;
        }
        
        CGFloat pageWidth = scrollView.frame.size.width;
        int page = floor((scrollView.contentOffset.x - pageWidth / 2)/pageWidth) + 1;
        pageControl.currentPage = page;
        
    }
    
    -(void)pageTurning:(UIPageControl *)pageController{
        NSInteger nextPage = [pageController currentPage];
        
        switch (nextPage) {
            case 0:
                scrollView.backgroundColor = [UIColor blueColor];
                break;
            case 1:
                scrollView.backgroundColor = [UIColor redColor];
                
            default:
                break;
        }
    }
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
        scrollView.delegate = self;
        
        [pageControl addTarget:self action:@selector(pageTurning:) forControlEvents:UIControlEventValueChanged];
        
        pageControl.currentPage = 0;
        
        [self pageTurning:pageControl];
        
        //self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        //self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    any ideas?
    12-02-2011 02:56 PM
LINK TO POST COPIED TO CLIPBOARD