- (void)viewWillAppear:(BOOL)animated {
// view controllers are created lazily
// in the meantime, load the array with placeholders which will be replaced on demand
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < pages; i++) {
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];
// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * pages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
[self loadScrollViewWithPage:0];
[self loadScrollViewWithPage:1];
CGRect rootViewBounds = self.parentViewController.view.bounds;
CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);
pageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (rootViewHeight - 20), rootViewWidth, 20)];
[pageLabel setBackgroundColor:[UIColor blackColor]];
[pageLabel setTextColor:[UIColor whiteColor]];
[pageLabel setTextAlignment:UITextAlignmentCenter];
pageLabel.text = [[NSString stringWithFormat:@"1 of %i",pages] retain];
[self.navigationController.view addSubview:pageLabel];
// [self.scrollView scrollRectToVisible:HELPZ animated:YES];
}