CS4521:   Mobile and Topics in Web Programming

iOS: the Deglate class

As shown below are the delegate files generated for us when we create a new iOS project.

  • AppDelegate.h and .m

 

 

What is a Delegate?

  • class that takes responsibility for doing certain tasks on behalf of another object

 

What is an Application Delegate?

  • Every iOS program has one (only) application delgate

  • does things on behalf of UIApplication class

  • responsible for application run loop and handles application-level functionality (routing input to appropriate controller class, etc)

  • At predefined times UIApplication will call methods if they are implemented in the application Delegate

    • applicationWillTerminate = method that will be called right before application ends

     

You don't need to know about innerworkings of UIApplicaitonDelegate just know the methods of Delegate class can be called by it and when and with what parameters. Then you implement the methods you want.

 

 

 

ONLY add method declarations to .h and implementations to .m from the UIApplicaitonDelegate class
you wish to implement --- maybe nothing!!!!

 

 

Example AppNameAppDelegate.h file --default no added code

//
//  AppDelegate.h
//  ButtonSingleView_SecondView
//
//  Created by student on 11/23/14.
//  Copyright (c) 2014 grewe. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

 

 

 

HOW DOES the Application's ViewController (first Interface) get initialized?

 

Upon Launch the ViewController's method viewDidLoad = method that will be called when the application is launched and you can implement it to Initialize your app

DEFAULT method will use the corresponding interface defined in StoryBoard or xib file associated with it (project setup or code)

//
//  ViewController.m
//  ButtonSingleView_SecondView
//
//  Created by student on 11/23/14.
//  Copyright (c) 2014 grewe. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

© Lynne Grewe