SlideShare a Scribd company logo
1 of 47
Download to read offline
Andrei Raifura iOS Department Manager, YOPESO
#CodeWăy
UIViewController:
Fighting the monster
Overview
• The“monster”problem
• A practical solution
• View Controllers from historical perspective
Historical approach
Historical approach
Historical approach
Meet UIViewController
• Contains the View
• Manages the View
• Plays well with Interface Builder
• Defines a screen
• Conforms to MVC
Conceptual MVC
Model View
Controller
Update
Update
User ActionNotify
ViewController’s MVC
Model ViewController
View
Update
Notify
Meet UIViewController
The problem
Things changed
ViewController is the same (almost)
Model ViewController
View
Update
Notify
ViewController’s Responsibilities
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
View setup
@interface FMViewController ()
@property (weak, nonatomic) IBOutlet UITextField *usernameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UIView *feedbackView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
@end
@implementation FMViewController
View setup
- (void)viewDidLoad {
[super viewDidLoad];
self.myButton.titleLabel.font = myCustomFont;
UIImage *stretchableImage =
[self.myButton setBackgroundImage:stretchableImage
forControlState:UIControlStateNormal];
}
ViewController’s Responsibilities
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
View layout
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.myLabel.frame = /* ... */
self.myButton.frame = /* ... */
}
View layout
ViewController’s Responsibilities
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
ViewController’s Responsibilities
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
Navigation logic
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
id item = [self itemAtIndexPath:indexPath];
DetailsViewController *detailsVC
= [[DetailsViewController alloc] initWithItem:item];
[self.navigationController pushViewController:detailsVC
animated:YES];
}
ViewController’s Responsibilities
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
Core Data code
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
ViewController’s Responsibilities
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
ViewController’s Responsibilities
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
Decision making code
DetailsViewController *detailsVC = /* ... */;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// display details in the split view controller's
// details pane
} else {
// push details to the current navigation controller
}
ViewController’s Responsibilities
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
iOS Architecture
Looking into a View Controller
Looking for a solution
ViewController’s Responsibilities
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
ViewController’s Responsibilities
• View layout
• View management code
• Navigation logic
• View setup
• Core Data and NSFetchedResultsController code
• Delegate methods
• Other“decision making”code
Demo
Reduced Responsibilities
• View layout
• View management code
• View setup
View Controller issues
• Cannot be tested (using unit tests)
• Requires changes when the UI is changed
ViewController’s MVC
Model ViewController
View
Update
Notify
ViewController’s MVC
ViewController
View
ViewController’s MVC
ViewController View
Update
User Action
Demo
• Use View Models to encapsulate the information the view displays
• Put the IBOutlets in the private interface
• Create classes for views
• Use XIBs to define your layout
• Use a delegate to communicate asynchronous events from the view
• View keeps the datasources
Separate View from View Controller
• Testable View Controllers
• Ability to change the View without touching the View Controller
• More granular code
• It plays well with MVVM and VIPER concepts
Advantages
• Cannot use storyboards
• May lead to class explosion
• Requires some glue code
Disadvantages
One more thing?
Summary
• The“monster”problem
• A practical solution
• View Controllers from historical perspective
Questions?
Contacts
Raifura Andrei
iOS Department Manager, YOPESO
andrei.raifura@yopeso.com
thelvis4@gmail.com
#CodeWăy
UIViewController: Fighting the monster | Andrei Raifura | CodeWay 2015

More Related Content

More from YOPESO

Waiting on Machines
Waiting on MachinesWaiting on Machines
Waiting on MachinesYOPESO
 
User Interface that works | Sergiu Puscas | CodeWeek 2015
User Interface that works | Sergiu Puscas | CodeWeek 2015User Interface that works | Sergiu Puscas | CodeWeek 2015
User Interface that works | Sergiu Puscas | CodeWeek 2015YOPESO
 
What's the deal with UX Design? | Sergiu Tulgara | CodeWeek 2015
What's the deal with UX Design? | Sergiu Tulgara | CodeWeek 2015What's the deal with UX Design? | Sergiu Tulgara | CodeWeek 2015
What's the deal with UX Design? | Sergiu Tulgara | CodeWeek 2015YOPESO
 
TDD, the way to better software | Dan Ursu | CodeWay 2015
TDD, the way to better software | Dan Ursu | CodeWay 2015TDD, the way to better software | Dan Ursu | CodeWay 2015
TDD, the way to better software | Dan Ursu | CodeWay 2015YOPESO
 
Inheritance - the myth of code reuse | Andrei Raifura | CodeWay 2015
Inheritance - the myth of code reuse | Andrei Raifura | CodeWay 2015Inheritance - the myth of code reuse | Andrei Raifura | CodeWay 2015
Inheritance - the myth of code reuse | Andrei Raifura | CodeWay 2015YOPESO
 
Healthy mind in a healthy code | Oleg Anghelov | CodeWay 2015
Healthy mind in a healthy code | Oleg Anghelov | CodeWay 2015Healthy mind in a healthy code | Oleg Anghelov | CodeWay 2015
Healthy mind in a healthy code | Oleg Anghelov | CodeWay 2015YOPESO
 

More from YOPESO (6)

Waiting on Machines
Waiting on MachinesWaiting on Machines
Waiting on Machines
 
User Interface that works | Sergiu Puscas | CodeWeek 2015
User Interface that works | Sergiu Puscas | CodeWeek 2015User Interface that works | Sergiu Puscas | CodeWeek 2015
User Interface that works | Sergiu Puscas | CodeWeek 2015
 
What's the deal with UX Design? | Sergiu Tulgara | CodeWeek 2015
What's the deal with UX Design? | Sergiu Tulgara | CodeWeek 2015What's the deal with UX Design? | Sergiu Tulgara | CodeWeek 2015
What's the deal with UX Design? | Sergiu Tulgara | CodeWeek 2015
 
TDD, the way to better software | Dan Ursu | CodeWay 2015
TDD, the way to better software | Dan Ursu | CodeWay 2015TDD, the way to better software | Dan Ursu | CodeWay 2015
TDD, the way to better software | Dan Ursu | CodeWay 2015
 
Inheritance - the myth of code reuse | Andrei Raifura | CodeWay 2015
Inheritance - the myth of code reuse | Andrei Raifura | CodeWay 2015Inheritance - the myth of code reuse | Andrei Raifura | CodeWay 2015
Inheritance - the myth of code reuse | Andrei Raifura | CodeWay 2015
 
Healthy mind in a healthy code | Oleg Anghelov | CodeWay 2015
Healthy mind in a healthy code | Oleg Anghelov | CodeWay 2015Healthy mind in a healthy code | Oleg Anghelov | CodeWay 2015
Healthy mind in a healthy code | Oleg Anghelov | CodeWay 2015
 

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Recently uploaded (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

UIViewController: Fighting the monster | Andrei Raifura | CodeWay 2015