PageControl页面处理

时间:2012-12-09 17:58:25

标签: iphone xcode

我正在尝试将UIPageControl与我的UIScrollView一起使用。看来我正在做一些不正确的事情导致页面总是设置为一个。

这是我的ViewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];

    scrollView.delegate = self;

    UIImageView *imgView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tutorialScreen1.png"]];
    imgView1.frame = CGRectMake(0, 0, 320, 436);
    [scrollView addSubview:imgView1];

    UIImageView *imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tutorialScreen2.png"]];
    imgView2.frame = CGRectMake(320, 0, 320, 436);
    [scrollView addSubview:imgView2];

    UIImageView *imgView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tutorialScreen3.png"]];
    imgView3.frame = CGRectMake(640, 0, 320, 436);
    [scrollView addSubview:imgView3];

    scrollView.contentSize = CGSizeMake(960, 436);

    pageControl = [[UIPageControl alloc] init];

    [pageControl setNumberOfPages:3];
    [pageControl setCurrentPage:0];    
}

这是我的UIScrollView委托方法:

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollViewx{
    NSLog(@"%f",scrollView.contentOffset.x);
    NSLog(@"%f",(scrollViewx.contentOffset.x / 320));
    pageControl.currentPage = ((scrollViewx.contentOffset.x / 320));
}

这是y .h文件:

@interface TutorialViewController : UIViewController <UIScrollViewDelegate>

@property (nonatomic,strong) IBOutlet UIScrollView *scrollView;
@property (nonatomic,strong) IBOutlet UIPageControl *pageControl;

@end

有没有人知道它为什么不改变?当然,我确保我的UIPageControl已连接到它的实例。

感谢您的帮助......

1 个答案:

答案 0 :(得分:0)

行。点没有改变,因为你创建了一个新的UIPageControl,而不是使用你在IB中设置的那个。取出:pageControl = [[UIPageControl alloc] init];

相关问题