SlideShare a Scribd company logo
1 of 31
Download to read offline
iOS:	
  View	
  Controllers	
  

            Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
Screen,	
  Window,	
  UIView	
  
View	
  Controller	
  
Several	
  Screens?	
  
•  Typical	
  iOS	
  app	
  has	
  several	
  screens	
  
•  Usually	
  this	
  is	
  implemented	
  so	
  that	
  you	
  have	
  
   several	
  View	
  Controller	
  classes,	
  one	
  for	
  each	
  
   screen	
  
•  UIViewController	
  class	
  holds	
  a	
  property	
  that	
  
   points	
  to	
  UIView	
  (which	
  is	
  visible	
  in	
  the	
  
   screen)	
  
UIViewController	
  
#import <UIKit/UIKit.h>

@interface MainScreenViewController :
UIViewController

@end
Adding	
  a	
  BuIon	
  to	
  the	
  View	
  of	
  
                 ViewController	
  
- (void)viewDidLoad
{
    [super viewDidLoad];

    // Initialize a view, this could be a custom view also..
    UIButton* button =
            [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setTitle:@"Main1" forState: UIControlStateNormal];

    // Add the view to the controller
    [self setView: button];
}
Root	
  Controller	
  
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    MainScreenViewController* mainscreen = [[MainScreenViewController alloc] init];

    [[self window] setRootViewController:mainscreen];


    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
Root	
  Controller?	
  
•  SeKng	
  a	
  view	
  controller	
  as	
  root	
  controller	
  of	
  a	
  
   window	
  
    –  Add’s	
  view	
  controller’s	
  view	
  to	
  window	
  
    –  AutomaMcally	
  resizes	
  the	
  view	
  to	
  be	
  the	
  same	
  size	
  
       than	
  window	
  
XIB?	
  
•  It’s	
  usually	
  wise	
  to	
  implement	
  the	
  UI	
  in	
  xib	
  
•  You	
  can	
  create	
  new	
  empty	
  xib	
  file	
  to	
  your	
  
   project	
  
•  Set	
  the	
  File’s	
  owner	
  to	
  the	
  view	
  controller!	
  
View	
  Controller	
  and	
  View	
  
•  The	
  View	
  Controller	
  has	
  a	
  property	
  View	
  
•  In	
  XIB,	
  you	
  can	
  add	
  to	
  canvas	
  a	
  UIView	
  and	
  
   connect	
  it	
  as	
  outlet	
  of	
  the	
  view	
  controller’s	
  
   view!	
  
Content	
  View	
  Controller	
  vs	
  
           Container	
  View	
  Controller	
  
•  Content	
  View	
  Controller	
  
   –  Content	
  on	
  the	
  screen	
  using	
  Views	
  
   –  Usually	
  has	
  a	
  .xib	
  
•  Container	
  View	
  Controller	
  
   –  Content	
  owned	
  by	
  other	
  View	
  Controllers	
  
   –  Parent	
  to	
  other	
  controllers	
  
   –  Container	
  manages	
  a	
  API	
  to	
  manage	
  children	
  (change	
  
      screens)	
  
   –  For	
  example:	
  Tab	
  Bar	
  Controller,	
  Naviga<on	
  
      Controller	
  
Tab	
  Bar	
  Controller	
  
NavigaMon	
  Controller	
  
Complex	
  App	
  
UITABVIEWCONTROLLER	
  
UITabController	
  
•  To	
  change	
  a	
  view	
  controller	
  
•  Holds	
  array	
  of	
  view	
  controllers	
  
•  Really	
  easy	
  to	
  implement	
  
	
  
UITabController:	
  Add	
  Titles	
  
•  ViewController	
  class	
  has	
  a	
  property	
  
   tabBarItem!	
  
Init	
  in	
  more	
  detail	
  
•  The	
  init	
  method	
  here	
  loads	
  the	
  xib-­‐file…	
  you	
  
   pass	
  the	
  xib-­‐file	
  name	
  to	
  the	
  method:	
  
Init	
  in	
  more	
  detail	
  
•  When	
  iniMalizing	
  the	
  controller 	
  	
  
    –  	
  SettingsViewController* settingsview =
       [[SettingsViewController alloc] init];
•  This	
  is	
  equivalent	
  to	
  this!	
  
    –  SettingsViewController* settingsview =
       [[SettingsViewController alloc]
       initWithNibName:nil bundle:nil];
•  What	
  happens	
  if	
  nibname	
  is	
  nil?	
  
    –  Search	
  for	
  a	
  xib	
  file	
  whose	
  name	
  is	
  the	
  same	
  as	
  your	
  
       class	
  and	
  search	
  inside	
  of	
  this	
  app	
  bundle!
UINAVIGATIONCONTROLLER	
  
About	
  Nav	
  Controller	
  
•  Presents	
  data	
  organized	
  hierarchically	
  
•  Stack-­‐based	
  collecMon	
  of	
  view	
  controllers	
  
    –  Stack:	
  path	
  taken	
  by	
  the	
  user	
  through	
  the	
  
       hierarchical	
  data	
  
    –  BoIom	
  stack:	
  starMng	
  point,	
  top	
  stack:	
  current	
  
       posiMon	
  
•  Holds	
  
    –  NavigaMon	
  bar,	
  a	
  back	
  buIon	
  and	
  opMonal	
  custom	
  
       views	
  
iOS: View Controllers
iOS: View Controllers
CreaMng	
  a	
  UINavigaMonController	
  
// Create view controller
SettingsViewController* settingsview = [[SettingsViewController
alloc] init];

// Create navigation controller.
// Initialize it with the first screen
UINavigationController* navController =
     [[UINavigationController alloc]
           initWithRootViewController:settingsview];

// Add navigation controller to window
 [[self window] setRootViewController:navController];
Modifying	
  NavigaMon	
  Stack	
  
•  Add	
  another	
  view	
  to	
  stack	
  
    –  [navController
       pushViewController:otherViewController
       animated:YES];
•  To	
  get	
  pointer	
  to	
  navController	
  in	
  
   ViewController,	
  use	
  
   •  [[self
      navigationController] pushViewController:otherV
      iewController animated:YES];
Passing	
  informaMon	
  
// Get text from UITextField
NSString* myText = [[self someTextField] text];

// Create the view controller
SettingsView1Controller* sv1 = [[SettingsView1Controller alloc] init];

// Pass the text to the view controller
[sv1 setText: myText];

// Push the view controller to nav controller. viewDidLoad is
// called!
[[self navigationController] pushViewController:sv1 animated:YES];
Receiving	
  informaMon	
  
@interface SettingsView1Controller : UIViewController
{
}

// Attribute and set+get methods for text
@property NSString* text;
@property IBOutlet UILabel* label;

* * *

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

     // Set the given text to label:
    [[self label] setText: [self text]];
}
The	
  Nav	
  Bar	
  
The	
  Nav	
  Bar	
  
UINavigaMonItem	
  
•  Set	
  a	
  Mtle	
  
     –  UINavigationItem *n = [self navigationItem];
     –  [n setTitle:@"Settings"];

•  Other	
  properMes	
  
     –  MtleView	
  -­‐>	
  Can	
  have	
  any	
  view	
  on	
  navigaMon	
  bar	
  
     –  rightBarBuIonItem	
  -­‐>	
  another	
  buIon	
  to	
  the	
  right	
  
     –  See	
  documentaMon	
  
Right	
  BuIon	
  

More Related Content

What's hot

はじめてのWKInterfaceController
はじめてのWKInterfaceControllerはじめてのWKInterfaceController
はじめてのWKInterfaceControllertoyship
 
An overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endAn overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endSaeid Zebardast
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJSRajthilakMCA
 
Mobile Software Engineering Crash Course - C03 Android
Mobile Software Engineering Crash Course - C03 AndroidMobile Software Engineering Crash Course - C03 Android
Mobile Software Engineering Crash Course - C03 AndroidMohammad Shaker
 
JavaScript MV* Framework - Making the Right Choice
JavaScript MV* Framework - Making the Right ChoiceJavaScript MV* Framework - Making the Right Choice
JavaScript MV* Framework - Making the Right ChoiceDmitry Sheiko
 
iOS UIStoryboard presentation
iOS UIStoryboard presentationiOS UIStoryboard presentation
iOS UIStoryboard presentationGerald Kim
 
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)🎤 Hanno Embregts 🎸
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSGunnar Hillert
 
Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Max Klymyshyn
 
Motion design in FIori
Motion design in FIoriMotion design in FIori
Motion design in FIoriRoman Rommel
 

What's hot (16)

はじめてのWKInterfaceController
はじめてのWKInterfaceControllerはじめてのWKInterfaceController
はじめてのWKInterfaceController
 
An overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endAn overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-end
 
IOS Storyboards
IOS StoryboardsIOS Storyboards
IOS Storyboards
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 
Mobile Software Engineering Crash Course - C03 Android
Mobile Software Engineering Crash Course - C03 AndroidMobile Software Engineering Crash Course - C03 Android
Mobile Software Engineering Crash Course - C03 Android
 
JavaScript MV* Framework - Making the Right Choice
JavaScript MV* Framework - Making the Right ChoiceJavaScript MV* Framework - Making the Right Choice
JavaScript MV* Framework - Making the Right Choice
 
iOS UIStoryboard presentation
iOS UIStoryboard presentationiOS UIStoryboard presentation
iOS UIStoryboard presentation
 
IOS APPs Revision
IOS APPs RevisionIOS APPs Revision
IOS APPs Revision
 
Angular Classy
Angular ClassyAngular Classy
Angular Classy
 
Android development session 4 - Fragments
Android development   session 4 - FragmentsAndroid development   session 4 - Fragments
Android development session 4 - Fragments
 
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
 
Intro to UI-Router/TypeScript
Intro to UI-Router/TypeScriptIntro to UI-Router/TypeScript
Intro to UI-Router/TypeScript
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 
Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013
 
Motion design in FIori
Motion design in FIoriMotion design in FIori
Motion design in FIori
 
Synapse india mobile apps update
Synapse india mobile apps updateSynapse india mobile apps update
Synapse india mobile apps update
 

Viewers also liked

04 Model View Controller
04 Model View Controller04 Model View Controller
04 Model View ControllerMahmoud
 
06 View Controllers
06 View Controllers06 View Controllers
06 View ControllersMahmoud
 
01 Introduction
01 Introduction01 Introduction
01 IntroductionMahmoud
 
02 Objective C
02 Objective C02 Objective C
02 Objective CMahmoud
 
03 Custom Classes
03 Custom Classes03 Custom Classes
03 Custom ClassesMahmoud
 
CS193P Lecture 5 View Animation
CS193P Lecture 5 View AnimationCS193P Lecture 5 View Animation
CS193P Lecture 5 View Animationonoaonoa
 

Viewers also liked (9)

09 Data
09 Data09 Data
09 Data
 
04 Model View Controller
04 Model View Controller04 Model View Controller
04 Model View Controller
 
06 View Controllers
06 View Controllers06 View Controllers
06 View Controllers
 
01 Introduction
01 Introduction01 Introduction
01 Introduction
 
02 Objective C
02 Objective C02 Objective C
02 Objective C
 
03 Custom Classes
03 Custom Classes03 Custom Classes
03 Custom Classes
 
05 Views
05 Views05 Views
05 Views
 
CS193P Lecture 5 View Animation
CS193P Lecture 5 View AnimationCS193P Lecture 5 View Animation
CS193P Lecture 5 View Animation
 
Animation in iOS
Animation in iOSAnimation in iOS
Animation in iOS
 

Similar to iOS: View Controllers

iPhone Development: Multiple Views
iPhone Development: Multiple ViewsiPhone Development: Multiple Views
iPhone Development: Multiple ViewsJussi Pohjolainen
 
iOS: Implementing a Custom View
iOS: Implementing a Custom ViewiOS: Implementing a Custom View
iOS: Implementing a Custom ViewJussi Pohjolainen
 
Intro to UIKit • Made by Many
Intro to UIKit • Made by ManyIntro to UIKit • Made by Many
Intro to UIKit • Made by Manykenatmxm
 
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
Session 15  - Working with Image, Scroll, Collection, Picker, and Web ViewSession 15  - Working with Image, Scroll, Collection, Picker, and Web View
Session 15 - Working with Image, Scroll, Collection, Picker, and Web ViewVu Tran Lam
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's NewNascentDigital
 
아이폰강의(5) pdf
아이폰강의(5) pdf아이폰강의(5) pdf
아이폰강의(5) pdfsunwooindia
 
Session 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab barSession 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab barVu Tran Lam
 
Quick Start to iOS Development
Quick Start to iOS DevelopmentQuick Start to iOS Development
Quick Start to iOS DevelopmentJussi Pohjolainen
 
Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Michael Shrove
 
Synapse india reviews on i phone and android os
Synapse india reviews on i phone and android osSynapse india reviews on i phone and android os
Synapse india reviews on i phone and android ossaritasingh19866
 
Leaving Interface Builder Behind
Leaving Interface Builder BehindLeaving Interface Builder Behind
Leaving Interface Builder BehindJohn Wilker
 
Custom cell in objective c
Custom cell in objective cCustom cell in objective c
Custom cell in objective cVishal Verma
 
Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Formacion en movilidad: Conceptos de desarrollo en iOS (III) Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Formacion en movilidad: Conceptos de desarrollo en iOS (III) Mobivery
 
Everything You (N)ever Wanted to Know about Testing View Controllers
Everything You (N)ever Wanted to Know about Testing View ControllersEverything You (N)ever Wanted to Know about Testing View Controllers
Everything You (N)ever Wanted to Know about Testing View ControllersBrian Gesiak
 

Similar to iOS: View Controllers (20)

I os 11
I os 11I os 11
I os 11
 
iPhone Development: Multiple Views
iPhone Development: Multiple ViewsiPhone Development: Multiple Views
iPhone Development: Multiple Views
 
iOS: Implementing a Custom View
iOS: Implementing a Custom ViewiOS: Implementing a Custom View
iOS: Implementing a Custom View
 
занятие6
занятие6занятие6
занятие6
 
Intro to UIKit • Made by Many
Intro to UIKit • Made by ManyIntro to UIKit • Made by Many
Intro to UIKit • Made by Many
 
IOS- Designing with ui tool bar in ios
IOS-  Designing with ui tool bar in iosIOS-  Designing with ui tool bar in ios
IOS- Designing with ui tool bar in ios
 
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
Session 15  - Working with Image, Scroll, Collection, Picker, and Web ViewSession 15  - Working with Image, Scroll, Collection, Picker, and Web View
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's New
 
아이폰강의(5) pdf
아이폰강의(5) pdf아이폰강의(5) pdf
아이폰강의(5) pdf
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Session 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab barSession 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab bar
 
004
004004
004
 
Quick Start to iOS Development
Quick Start to iOS DevelopmentQuick Start to iOS Development
Quick Start to iOS Development
 
Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)
 
Synapse india reviews on i phone and android os
Synapse india reviews on i phone and android osSynapse india reviews on i phone and android os
Synapse india reviews on i phone and android os
 
iOS
iOSiOS
iOS
 
Leaving Interface Builder Behind
Leaving Interface Builder BehindLeaving Interface Builder Behind
Leaving Interface Builder Behind
 
Custom cell in objective c
Custom cell in objective cCustom cell in objective c
Custom cell in objective c
 
Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Formacion en movilidad: Conceptos de desarrollo en iOS (III) Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Formacion en movilidad: Conceptos de desarrollo en iOS (III)
 
Everything You (N)ever Wanted to Know about Testing View Controllers
Everything You (N)ever Wanted to Know about Testing View ControllersEverything You (N)ever Wanted to Know about Testing View Controllers
Everything You (N)ever Wanted to Know about Testing View Controllers
 

More from Jussi Pohjolainen

libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferencesJussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationJussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDXJussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 

More from Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Recently uploaded

Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...DianaGray10
 
Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Muhammad Tiham Siddiqui
 
Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updateadam112203
 
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechWebinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechProduct School
 
How to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptxHow to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptxKaustubhBhavsar6
 
EMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarEMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarThousandEyes
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and businessFrancesco Corti
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1DianaGray10
 
The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)IES VE
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0DanBrown980551
 
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc
 
Where developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingWhere developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingFrancesco Corti
 
How to release an Open Source Dataweave Library
How to release an Open Source Dataweave LibraryHow to release an Open Source Dataweave Library
How to release an Open Source Dataweave Libraryshyamraj55
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfTejal81
 
UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3DianaGray10
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4DianaGray10
 
Technical SEO for Improved Accessibility WTS FEST
Technical SEO for Improved Accessibility  WTS FESTTechnical SEO for Improved Accessibility  WTS FEST
Technical SEO for Improved Accessibility WTS FESTBillieHyde
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfInfopole1
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosErol GIRAUDY
 

Recently uploaded (20)

Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...
 
Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)
 
Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 update
 
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechWebinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
 
How to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptxHow to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptx
 
EMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarEMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? Webinar
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and business
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile Brochure
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1
 
The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0
 
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
 
Where developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingWhere developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is going
 
How to release an Open Source Dataweave Library
How to release an Open Source Dataweave LibraryHow to release an Open Source Dataweave Library
How to release an Open Source Dataweave Library
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
 
UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4
 
Technical SEO for Improved Accessibility WTS FEST
Technical SEO for Improved Accessibility  WTS FESTTechnical SEO for Improved Accessibility  WTS FEST
Technical SEO for Improved Accessibility WTS FEST
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdf
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenarios
 

iOS: View Controllers

  • 1. iOS:  View  Controllers   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 4. Several  Screens?   •  Typical  iOS  app  has  several  screens   •  Usually  this  is  implemented  so  that  you  have   several  View  Controller  classes,  one  for  each   screen   •  UIViewController  class  holds  a  property  that   points  to  UIView  (which  is  visible  in  the   screen)  
  • 5. UIViewController   #import <UIKit/UIKit.h> @interface MainScreenViewController : UIViewController @end
  • 6. Adding  a  BuIon  to  the  View  of   ViewController   - (void)viewDidLoad { [super viewDidLoad]; // Initialize a view, this could be a custom view also.. UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setTitle:@"Main1" forState: UIControlStateNormal]; // Add the view to the controller [self setView: button]; }
  • 7. Root  Controller   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. MainScreenViewController* mainscreen = [[MainScreenViewController alloc] init]; [[self window] setRootViewController:mainscreen]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }
  • 8. Root  Controller?   •  SeKng  a  view  controller  as  root  controller  of  a   window   –  Add’s  view  controller’s  view  to  window   –  AutomaMcally  resizes  the  view  to  be  the  same  size   than  window  
  • 9. XIB?   •  It’s  usually  wise  to  implement  the  UI  in  xib   •  You  can  create  new  empty  xib  file  to  your   project   •  Set  the  File’s  owner  to  the  view  controller!  
  • 10. View  Controller  and  View   •  The  View  Controller  has  a  property  View   •  In  XIB,  you  can  add  to  canvas  a  UIView  and   connect  it  as  outlet  of  the  view  controller’s   view!  
  • 11. Content  View  Controller  vs   Container  View  Controller   •  Content  View  Controller   –  Content  on  the  screen  using  Views   –  Usually  has  a  .xib   •  Container  View  Controller   –  Content  owned  by  other  View  Controllers   –  Parent  to  other  controllers   –  Container  manages  a  API  to  manage  children  (change   screens)   –  For  example:  Tab  Bar  Controller,  Naviga<on   Controller  
  • 16. UITabController   •  To  change  a  view  controller   •  Holds  array  of  view  controllers   •  Really  easy  to  implement    
  • 17. UITabController:  Add  Titles   •  ViewController  class  has  a  property   tabBarItem!  
  • 18. Init  in  more  detail   •  The  init  method  here  loads  the  xib-­‐file…  you   pass  the  xib-­‐file  name  to  the  method:  
  • 19. Init  in  more  detail   •  When  iniMalizing  the  controller     –   SettingsViewController* settingsview = [[SettingsViewController alloc] init]; •  This  is  equivalent  to  this!   –  SettingsViewController* settingsview = [[SettingsViewController alloc] initWithNibName:nil bundle:nil]; •  What  happens  if  nibname  is  nil?   –  Search  for  a  xib  file  whose  name  is  the  same  as  your   class  and  search  inside  of  this  app  bundle!
  • 21. About  Nav  Controller   •  Presents  data  organized  hierarchically   •  Stack-­‐based  collecMon  of  view  controllers   –  Stack:  path  taken  by  the  user  through  the   hierarchical  data   –  BoIom  stack:  starMng  point,  top  stack:  current   posiMon   •  Holds   –  NavigaMon  bar,  a  back  buIon  and  opMonal  custom   views  
  • 24. CreaMng  a  UINavigaMonController   // Create view controller SettingsViewController* settingsview = [[SettingsViewController alloc] init]; // Create navigation controller. // Initialize it with the first screen UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:settingsview]; // Add navigation controller to window [[self window] setRootViewController:navController];
  • 25. Modifying  NavigaMon  Stack   •  Add  another  view  to  stack   –  [navController pushViewController:otherViewController animated:YES]; •  To  get  pointer  to  navController  in   ViewController,  use   •  [[self navigationController] pushViewController:otherV iewController animated:YES];
  • 26. Passing  informaMon   // Get text from UITextField NSString* myText = [[self someTextField] text]; // Create the view controller SettingsView1Controller* sv1 = [[SettingsView1Controller alloc] init]; // Pass the text to the view controller [sv1 setText: myText]; // Push the view controller to nav controller. viewDidLoad is // called! [[self navigationController] pushViewController:sv1 animated:YES];
  • 27. Receiving  informaMon   @interface SettingsView1Controller : UIViewController { } // Attribute and set+get methods for text @property NSString* text; @property IBOutlet UILabel* label; * * * - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. // Set the given text to label: [[self label] setText: [self text]]; }
  • 30. UINavigaMonItem   •  Set  a  Mtle   –  UINavigationItem *n = [self navigationItem]; –  [n setTitle:@"Settings"]; •  Other  properMes   –  MtleView  -­‐>  Can  have  any  view  on  navigaMon  bar   –  rightBarBuIonItem  -­‐>  another  buIon  to  the  right   –  See  documentaMon