Multiview Apps, Networking Android




CS185c

Chris Pollett

Mar 7, 2012

More on Multiview Applications

Creating Our View Controller and Nib Files

Modifying the App Delegate Header

Modifying the App Delegate Implementation

SwitchViewController.h

Changing the First Responder

What Custom Class Looks like in Identity Inspector

Adding a Toolbar

SwitchViewController Implementation

#import "SwitchViewController.h"
#import "BlueViewController.h"
#import "YellowViewController.h"

@implementation SwitchViewController

@synthesize blueViewController;
@synthesize yellowViewController;

// ...
- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.

    if(self.blueViewController.view.superview == nil) {
        self.blueViewController = nil;
    } else {
        self.yellowViewController = nil;
    }
}

// ...

- (void)viewDidLoad {
        // set up blue controller
	self.blueViewController = [[BlueViewController alloc] 
           initWithNibName:@"BlueView" bundle:nil];
        // initial use blue view
	[self.view insertSubview:self.blueViewController.view atIndex: 0]; 
             //index 0 behind everything
	[super viewDidLoad];
}

- (void) switchViews:(id)sender
{
	if(self.yellowViewController.view.superview == nil)
	{
        if(self.yellowViewController == nil) {
            self.yellowViewController = [[YellowViewController alloc] 
                initWithNibName:@"YellowView" bundle:nil];
        }
		[self.blueViewController.view removeFromSuperview];
		[self.view insertSubview:self.yellowViewController.view atIndex:0];
	} else {

        //check if not Blue View
        if(self.blueViewController == nil) {
            self.blueViewController = [[BlueViewController alloc] 
                initWithNibName:@"BlueView" bundle:nil];
        }
        [self.yellowViewController.view removeFromSuperview];
        [self.view insertSubview:self.blueViewController.view atIndex:0];

    }
	
}

//... rest of boilerplate code unchanged



@end

Implementing Content Views

BlueViewController Implementation

Animating the Transition

Overview of Networking

Clients and Servers

Checking Network Status