utilising view controllers

36
U"lising View Controllers Daniel Tull

Upload: danielctull

Post on 22-Nov-2014

2.990 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Utilising View Controllers

U"lising View ControllersDaniel Tull

Page 2: Utilising View Controllers

A Small Plug...

Weather MapsSky+

Page 3: Utilising View Controllers

What is a view controller?

A class to manage user interface logic for a view.

Page 4: Utilising View Controllers

What is a view controller?

Provides the structure and functionality of the Apple‐developed UI design patterns.

Page 5: Utilising View Controllers

What is a view controller?Navigation Bar Title

Table View

Tab Bar‘More’ Tab Item

Bar ButtonNavigation Back Button

Page 6: Utilising View Controllers

Why use a view controller?

Almost zero code to use Tab and Navigation Bars. 

Use to display a modal view (like a login page).

Get a message when the orientation of the device changes so you can handle landscape mode.

Memory warnings enable you to avoid crashing out due to too many views in memory.

Page 7: Utilising View Controllers

Naviga"on Controller

Allows navigation through a hierarchy of view controllers.

You don’t need to write (much) code for it.

Page 8: Utilising View Controllers

Naviga"on Controller

Allows navigation through a hierarchy of view controllers. 

You don’t need to write (much) code for them.

Page 9: Utilising View Controllers

Naviga"on Controller

[self.navigationController pushViewController:vc animated:YES];

[self.navigationController popViewControllerAnimated:YES]; 

Page 10: Utilising View Controllers

Tab Bar Controllers

Allow quick switching of view controllers.

You don’t need to write (much) code for them; Send it an array of view controllers and it works!

Page 11: Utilising View Controllers

Tab Bar Controllers

Allow quick switching of view controllers.

You don’t need to write (much) code for them; Send it an array of view controllers and it works!

Page 12: Utilising View Controllers

Tab Bar Controllers

Allow quick switching of view controllers.

You don’t need to write (much) code for them; Send it an array of view controllers and it works!

Page 13: Utilising View Controllers

Subclassing UIViewController

Implement initWithNibName:bundle: if you need to  handle any speciOic logic when creating your view controller.

This Oinds the view XIB of the provided details and loads it for use.

The File Owner of the XIB is the view controller subclass, so we set that in Interface Builder.

Page 14: Utilising View Controllers

Subclassing UIViewController

Page 15: Utilising View Controllers

Subclassing UIViewController

Create an init method, because it’ll make life easier.

‐(id)init {

    return [self initWithNibName:@“MyView” bundle:nil];}

But still use the initWithNibName:bundle: method in your subclass rather than calling super!

Page 16: Utilising View Controllers

A View XIB for view controllers

Connecting the view controller’s view property to the UIView in Interface Builder.

Page 17: Utilising View Controllers

A View XIB for view controllers

Setting the view’s autosizing property to Olexible width and height will allow use inside any view controller structure. 

Page 18: Utilising View Controllers

Autorota"on

If you have set the view to Olexible width and height, it will resize to the new dimensions.

‐ (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    return YES;}

Giving subviews correct autoresizingMask properties will allow you to go landscape automatically.

Page 19: Utilising View Controllers

Autorota"on

Page 20: Utilising View Controllers

Autorota"on

Page 21: Utilising View Controllers

Autorota"on

Page 22: Utilising View Controllers

Autorota"on

Page 23: Utilising View Controllers

Autorota"on

Page 24: Utilising View Controllers

Autorota"on

Page 25: Utilising View Controllers

Autorota"on

Page 26: Utilising View Controllers

Autorota"on

Page 27: Utilising View Controllers

Crea"ng IBOutlets

@interface MyViewController : UIViewController {

    UIView *subView;

}

@property (nonatomic, retain) IBOutlet UIView *aSubview;

@end

The nib loading mechanism uses accessors, so you should declare outlets in property delcarations:

Page 28: Utilising View Controllers

Handling Memory Warnings

UIViewController

didRecieveMemoryWarning

view

Page 29: Utilising View Controllers

Handling Memory Warnings

UIViewController

didRecieveMemoryWarning

view

setView:

setView:nil

Page 30: Utilising View Controllers

Handling Memory Warnings

UIViewController

didRecieveMemoryWarning

view

setView:

setView:nil

Page 31: Utilising View Controllers

Handling Memory Warnings

MyViewController

UIView *aSubview; 

UITableView *table; 

DTGridView *grid; UILabel *label2; 

UILabel *label3; 

UILabel *label1; 

UIImage *image2; 

UIImage *image1; 

UIImage *image3;  UIImage *buQon3; 

UIView *subview; 

UIWebView *webView;  UISegmentedControl *segControl;

UIBuQon *buQon1;

UIBuQon *buQon2;

UISlider *slider;

view

Page 32: Utilising View Controllers

Handling Memory Warnings

MyViewController

didRecieveMemoryWarning

UIView *aSubview; 

UITableView *table; 

DTGridView *grid; UILabel *label2; 

UILabel *label3; 

UILabel *label1; 

UIImage *image2; 

UIImage *image1; 

UIImage *image3;  UIImage *buQon3; 

UIView *subview; 

UIWebView *webView;  UISegmentedControl *segControl;

UIBuQon *buQon1;

UIBuQon *buQon2;

UISlider *slider;

view

Page 33: Utilising View Controllers

Handling Memory Warnings

MyViewController

didRecieveMemoryWarning

setView:

UIView *aSubview; 

UITableView *table; 

DTGridView *grid; UILabel *label2; 

UILabel *label3; 

UILabel *label1; 

UIImage *image2; 

UIImage *image1; 

UIImage *image3;  UIImage *buQon3; 

UIView *subview; 

UIWebView *webView;  UISegmentedControl *segControl;

UIBuQon *buQon1;

UIBuQon *buQon2;

UISlider *slider;

view

setView:nil

Page 34: Utilising View Controllers

Handling Memory Warnings

MyViewController

didRecieveMemoryWarning

setView:

UIView *aSubview; 

UITableView *table; 

DTGridView *grid; UILabel *label2; 

UILabel *label3; 

UILabel *label1; 

UIImage *image2; 

UIImage *image1; 

UIImage *image3;  UIImage *buQon3; 

UIView *subview; 

UIWebView *webView;  UISegmentedControl *segControl;

UIBuQon *buQon1;

UIBuQon *buQon2;

UISlider *slider;

view

setView:nil

Page 35: Utilising View Controllers

Handling Memory Warnings

‐ (void)setView:(UIView *)aView {    if (!aView)        self.someSubview = nil;        [super setView:aView];}

‐ (void)dealloc {    [someSubview release];    someSubview = nil;}