For the more curious - Paging



I am working through the book and having a go at the “For more curious - Paging” section.

My HypnoTimeScrollAppDelegate is like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
       // Create the tabBarController
	UITabBarController *tabBarController = [[UITabBarController alloc] init];
	// Create a scrollbarview controller
	ScrollViewController *svc = [[ScrollViewController alloc] init];
	// Add the svc to the view controllers
	NSArray *viewControllers = [NSArray arrayWithObjects:svc, nil];
	// can release this now as the array is now holding them
	[svc release];
	// Attach the scrollview to the tab controller
	[tabBarController setViewControllers:viewControllers];
     [window setRootViewController:tabBarController];
	[tabBarController release];
	[self.window makeKeyAndVisible];
    return YES;

In my ScrollViewController.m I have programmatically created 2 views as it shows you on the last page of the chapter (p118). Now what I want to do is be able to scroll AND select a tab from the bottom. However I don’t understand what I should be doing. If I have created a ScrollViewController and added this to the TabBarController. How do I add my views to the tab controller - what should I be doing in the loadView?

Or is this something we come to later in the book?



In the loadView method of ScrollViewController, you’ll create a UIScrollView. That will be the “view” of that view controller. Also in loadView, you will add two UIView instances as subviews of that scroll view. Off the cuff (might typo something):

@implementation ScrollViewController
- (void)loadView
     UIScrollView *sv = [[[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
     [self setView:sv];

     CGRect bounds = [sv bounds];
     UIView *v = [[[UIView alloc] initWithFrame:bounds] autorelease];
     [v setBackgroundColor:[UIColor greenColor]];
     [sv addSubview:v];

    bounds.origin.x += bounds.size.width;
    v = [[[UIView alloc] initWithFrame:bounds] autorelease];
    [v setBackgroundColor:[UIColor blueColor]];
    [sv addSubview:v];

    // Then set up paging for the scroll view as shown in the book