Multiview Apps, Networking Android




CS175

Chris Pollett

Oct 20, 2014

Outline

More on Multiview Applications

Creating Our View Controller and Nib Files

The Default View Controller Initial Pass

Adding a Toolbar

ViewController Implementation Take Two

#import "ViewController.h"

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

@interface ViewController ()

@property (strong, nonatomic) YellowViewController *yellowViewController;
@property (strong, nonatomic) BlueViewController *blueViewController;

@end

@implementation ViewController

-(IBAction)switchViews:(id)sender
{
    if(!self.yellowViewController.view.superview) {
        if(!self.yellowViewController) {
            self.yellowViewController = [self.storyboard
                instantiateViewControllerWithIdentifier:@"Yellow"];
        }
        [self.blueViewController.view removeFromSuperview];
        [self.view insertSubview:self.yellowViewController.view atIndex:0];
    } else {
        if(!self.blueViewController) {
            self.blueViewController = [self.storyboard
                                         instantiateViewControllerWithIdentifier:@"Blue"];
        }
        [self.yellowViewController.view removeFromSuperview];
        [self.view insertSubview:self.blueViewController.view atIndex:0];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.blueViewController = [self.storyboard
                               instantiateViewControllerWithIdentifier:@"Blue"];
    // initial use blue view
    [self.view insertSubview:self.blueViewController.view atIndex: 0];
    //index 0 behind everything
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    if(!self.blueViewController.view.superview) {
        self.blueViewController = nil;
    } else {
        self.yellowViewController = nil;
    }
}

@end

Implementing Content Views

BlueViewController Implementation

Adding Controller's To Out Main Storyboard

Animating the Transition

Quiz

Which of the following is true?

  1. getResources().getConfiguration().orientation could be used to get the orientation of the current context in Android.
  2. On Android, we use the C function call sqlite3_open("/path/to/database", &database); to open a sqlite database.
  3. A Runnable interface is supposed to have a postDelayed method to indicate an event will be run in the future.

Overview of Networking

Clients and Servers

Checking Network Status