SlideShare a Scribd company logo
LOGIC & INTERFACE 
Building our App
OVERVIEW 
• Lesson 1: Introductions 
• Lesson 2: iOS specifics 
• Lesson 3: Data Model 
• Lesson 4: Logic (Controller) & Interface
LESSON 3: DATA MODEL 
• Hour 1: Storyboard 
• Hour 2: Creating & Editing 
• Hour 3: Display & Deleting Notes
Storyboard
Storyboard
Storyboard 
• Visual representation of iOS user interface (UI) 
• Shows screens of content and connections 
between screens. Screens referred to as 
“Scene” 
• 1 “Scene” represents 1 View Controller and 
Views 
• Many “views” can be placed on 1 “scene” (e.g. 
buttons, table views, text views). Think of views
Storyboard 
• Each scene has a dock (displays icons 
representing the top-level objects of the 
scene)
Storyboard 
• The “dock” is where we make connections 
between code in our View Controller and its 
Views (“visual objects on the scene”)
View Controllers 
• A storyboard displays View Controllers and 
corresponding Views visually
View Controllers 
• A storyboard displays View Controllers and 
corresponding Views visually
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
// Override point for customization after application launch. 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; 
UINavigationController *navigationController = [splitViewController.viewControllers lastObject]; 
splitViewController.delegate = (id)navigationController.topViewController; 
} 
return YES; 
} 
View Controllers
View Controllers
View Controllers 
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
View Controllers 
UINavigationController 
• Sub-class of UIViewController 
• a special View Controller that manages the navigation of 
hierarchical content
View Controllers 
UINavigationController 
• It is a “container” that embeds content of other View 
Controllers inside itself
Creating and Editing
View Controllers 
AppDelegate.m 
#import "AppDelegate.h" 
#import "Data.h" 
@implementation AppDelegate 
- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
[Data getAllNotes]; 
return YES; 
}
View Controllers 
MasterViewController.m 
#import “Data.h" 
- (void)insertNewObject:(id)sender 
{ 
if (!_objects) { 
_objects = [[NSMutableArray alloc] init]; 
} 
//[_objects insertObject:[NSDate date] atIndex:0]; 
NSString *key = [[NSDate date] description]; 
[Data setNote:kDefaultText forKey:key]; 
[Data setCurrentKey:key]; 
[_objects insertObject:key atIndex:0]; 
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
}
View Controllers 
DetailViewController.m 
#import “Data.h" 
- (void)setDetailItem:(id)newDetailItem 
{ 
if (_detailItem != newDetailItem) { 
_detailItem = newDetailItem; 
[Data setCurrentKey:_detailItem]; 
// Update the view. 
[self configureView]; 
} 
if (self.masterPopoverController != nil) { 
[self.masterPopoverController dismissPopoverAnimated:YES]; 
} 
}
View Controllers 
DetailViewController.m 
- (void)configureView 
{ 
NSString *currentNote = [[Data getAllNotes] objectForKey:[Data getCurrentKey]]; 
if (![currentNote isEqualToString:kDefaultText]) { 
self.tView.text = currentNote; 
} else { 
self.tView.text = @""; 
} 
[self.tView becomeFirstResponder]; 
}
View Controllers 
DetailViewController.m 
- (void)viewWillDisappear:(BOOL)animated 
{ 
if (![self.tView.text isEqualToString:@""]) { 
[Data setNoteForCurrentKey:self.tView.text]; 
} else { 
[Data removeNoteForKey:[Data getCurrentKey]]; 
} 
[Data saveNotes]; 
}
Displaying & Deleting
View Controllers 
MasterViewController.m 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath 
*)indexPath 
{ 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" 
forIndexPath:indexPath]; 
NSDate *object = _objects[indexPath.row]; 
cell.textLabel.text = [[Data getAllNotes] objectForKey:[object description]]; 
return cell; 
}
View Controllers 
MasterViewController.m 
- (void)makeObjects 
{ 
_objects = [NSMutableArray arrayWithArray:[[Data getAllNotes] allKeys]]; 
[_objects sortUsingComparator:^NSComparisonResult(id obj1, id obj2) { 
return [(NSDate *)obj2 compare:(NSDate *)obj1]; 
}]; 
}
View Controllers 
MasterViewController.m 
- (void)insertNewObject:(id)sender 
{ 
[self makeObjects]; 
if (!_objects) { 
_objects = [[NSMutableArray alloc] init]; 
} 
//[_objects insertObject:[NSDate date] atIndex:0]; 
NSString *key = [[NSDate date] description]; 
[Data setNote:kDefaultText forKey:key]; 
[Data setCurrentKey:key]; 
[_objects insertObject:key atIndex:0]; 
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
[self performSegueWithIdentifier:kDetailView sender:self]; 
}
View Controllers 
MasterViewController.m
View Controllers 
MasterViewController.m 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 
NSDate *object = _objects[indexPath.row]; 
self.detailViewController.detailItem = object; 
} 
} 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
if ([[segue identifier] isEqualToString:@"showDetail"]) { 
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
NSDate *object = _objects[indexPath.row]; 
[[segue destinationViewController] setDetailItem:object]; 
} 
}
View Controllers 
MasterViewController.m 
- (void)viewWillAppear:(BOOL)animated 
{ 
[super viewDidAppear:animated]; 
[self makeObjects]; 
[self.tableView reloadData]; 
}
View Controllers 
MasterViewController.m 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if (editingStyle == UITableViewCellEditingStyleDelete) { 
[Data removeNoteForKey:[_objects objectAtIndex:indexPath.row]]; 
[Data saveNotes]; 
[_objects removeObjectAtIndex:indexPath.row]; 
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
} else if (editingStyle == UITableViewCellEditingStyleInsert) { 
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table 
view. 
} 
}
OVERVIEW 
• Lesson 1: Introductions 
• Lesson 2: iOS specifics 
• Lesson 3: Data Model 
• Lesson 4: Logic (Controller) & Interface

More Related Content

PDF
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
PDF
Owasp orlando, april 13, 2016
PPTX
Oop presentation
PPTX
Introduction to Service Workers | Matteo Manchi
PDF
I os 04
PDF
Utilising the data attribute
PPTX
JQuery Overview
PDF
20120121
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
Owasp orlando, april 13, 2016
Oop presentation
Introduction to Service Workers | Matteo Manchi
I os 04
Utilising the data attribute
JQuery Overview
20120121

What's hot (20)

PDF
Programming Google apps with the G Suite APIs
PDF
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
PDF
Functional Reactive Programming - RxSwift
PDF
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
PPTX
Object Oriented Programing in JavaScript
PDF
iOS State Preservation and Restoration
PPTX
Goa tutorial
PPTX
Wix Automation - DIY - Testing BI Events
PDF
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
KEY
iOSDevCamp 2011 Core Data
PPTX
Mobile Developers Talks: Delve Mobile
PPTX
The next step, part 2
PPTX
Asynchronous programming
PPTX
No More Deadlocks; Asynchronous Programming in .NET
PDF
[4developers] The saga pattern v3- Robert Pankowiecki
PPT
Intorduction of Playframework
PPTX
Cnam azure 2014 mobile services
PDF
2 years after the first event - The Saga Pattern
PDF
Reactive Programming Patterns with RxSwift
PPT
jQuery for beginners
Programming Google apps with the G Suite APIs
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
Functional Reactive Programming - RxSwift
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
Object Oriented Programing in JavaScript
iOS State Preservation and Restoration
Goa tutorial
Wix Automation - DIY - Testing BI Events
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
iOSDevCamp 2011 Core Data
Mobile Developers Talks: Delve Mobile
The next step, part 2
Asynchronous programming
No More Deadlocks; Asynchronous Programming in .NET
[4developers] The saga pattern v3- Robert Pankowiecki
Intorduction of Playframework
Cnam azure 2014 mobile services
2 years after the first event - The Saga Pattern
Reactive Programming Patterns with RxSwift
jQuery for beginners
Ad

Viewers also liked (6)

PDF
とりあえず使うScalaz
PDF
Functional Programming, Is It Worth It?
PDF
An introduction to functional programming with Swift
PPTX
iOS Beginners Lesson 3
PDF
Functional Programming for OO Programmers (part 1)
PDF
Functional Programming for OO Programmers (part 2)
とりあえず使うScalaz
Functional Programming, Is It Worth It?
An introduction to functional programming with Swift
iOS Beginners Lesson 3
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 2)
Ad

Similar to iOS Beginners Lesson 4 (20)

PDF
201104 iphone navigation-based apps
PDF
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
PDF
Session 14 - Working with table view and search bar
PPTX
Android and IOS UI Development (Android 5.0 and iOS 9.0)
PDF
Modular View Controller Hierarchies
PDF
Intro to UIKit • Made by Many
PPTX
iOS Development (Part 2)
PDF
Swift
PDF
IOS APPs Revision
PDF
Using a model view-view model architecture for iOS apps
PDF
iOS Contact List Application Tutorial
PDF
iOS: Table Views
PDF
10 tips for a reusable architecture
PDF
아이폰강의(4) pdf
PPT
iOS Programming 101
PDF
iOS viper presentation
PDF
Creating Container View Controllers
PPTX
Table views
PPTX
iOS Beginners Lesson 2
PDF
iOS 101 - Xcode, Objective-C, iOS APIs
201104 iphone navigation-based apps
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
Session 14 - Working with table view and search bar
Android and IOS UI Development (Android 5.0 and iOS 9.0)
Modular View Controller Hierarchies
Intro to UIKit • Made by Many
iOS Development (Part 2)
Swift
IOS APPs Revision
Using a model view-view model architecture for iOS apps
iOS Contact List Application Tutorial
iOS: Table Views
10 tips for a reusable architecture
아이폰강의(4) pdf
iOS Programming 101
iOS viper presentation
Creating Container View Controllers
Table views
iOS Beginners Lesson 2
iOS 101 - Xcode, Objective-C, iOS APIs

More from Calvin Cheng (11)

PDF
FOSSASIA 2018 Self-Sovereign Identity with Hyperledger Indy/Sovrin
PDF
Hashgraph as Code
PPTX
iOS Beginners Lesson 1
PPTX
So, you want to build a Bluetooth Low Energy device?
PPT
Fabric
KEY
Learning iOS and hunting NSZombies in 3 weeks
KEY
Ladypy 01
KEY
zhng your vim
KEY
Django101 geodjango
KEY
Saving Gaia with GeoDjango
PDF
Agile Apps with App Engine
FOSSASIA 2018 Self-Sovereign Identity with Hyperledger Indy/Sovrin
Hashgraph as Code
iOS Beginners Lesson 1
So, you want to build a Bluetooth Low Energy device?
Fabric
Learning iOS and hunting NSZombies in 3 weeks
Ladypy 01
zhng your vim
Django101 geodjango
Saving Gaia with GeoDjango
Agile Apps with App Engine

Recently uploaded (20)

PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
L1 - Introduction to python Backend.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
System and Network Administraation Chapter 3
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Essential Infomation Tech presentation.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
CHAPTER 2 - PM Management and IT Context
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Design an Analysis of Algorithms II-SECS-1021-03
L1 - Introduction to python Backend.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PTS Company Brochure 2025 (1).pdf.......
Navsoft: AI-Powered Business Solutions & Custom Software Development
System and Network Administraation Chapter 3
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms I-SECS-1021-03
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Essential Infomation Tech presentation.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx

iOS Beginners Lesson 4

  • 1. LOGIC & INTERFACE Building our App
  • 2. OVERVIEW • Lesson 1: Introductions • Lesson 2: iOS specifics • Lesson 3: Data Model • Lesson 4: Logic (Controller) & Interface
  • 3. LESSON 3: DATA MODEL • Hour 1: Storyboard • Hour 2: Creating & Editing • Hour 3: Display & Deleting Notes
  • 6. Storyboard • Visual representation of iOS user interface (UI) • Shows screens of content and connections between screens. Screens referred to as “Scene” • 1 “Scene” represents 1 View Controller and Views • Many “views” can be placed on 1 “scene” (e.g. buttons, table views, text views). Think of views
  • 7. Storyboard • Each scene has a dock (displays icons representing the top-level objects of the scene)
  • 8. Storyboard • The “dock” is where we make connections between code in our View Controller and its Views (“visual objects on the scene”)
  • 9. View Controllers • A storyboard displays View Controllers and corresponding Views visually
  • 10. View Controllers • A storyboard displays View Controllers and corresponding Views visually
  • 11. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; UINavigationController *navigationController = [splitViewController.viewControllers lastObject]; splitViewController.delegate = (id)navigationController.topViewController; } return YES; } View Controllers
  • 13. View Controllers UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  • 14. View Controllers UINavigationController • Sub-class of UIViewController • a special View Controller that manages the navigation of hierarchical content
  • 15. View Controllers UINavigationController • It is a “container” that embeds content of other View Controllers inside itself
  • 17. View Controllers AppDelegate.m #import "AppDelegate.h" #import "Data.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [Data getAllNotes]; return YES; }
  • 18. View Controllers MasterViewController.m #import “Data.h" - (void)insertNewObject:(id)sender { if (!_objects) { _objects = [[NSMutableArray alloc] init]; } //[_objects insertObject:[NSDate date] atIndex:0]; NSString *key = [[NSDate date] description]; [Data setNote:kDefaultText forKey:key]; [Data setCurrentKey:key]; [_objects insertObject:key atIndex:0]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; }
  • 19. View Controllers DetailViewController.m #import “Data.h" - (void)setDetailItem:(id)newDetailItem { if (_detailItem != newDetailItem) { _detailItem = newDetailItem; [Data setCurrentKey:_detailItem]; // Update the view. [self configureView]; } if (self.masterPopoverController != nil) { [self.masterPopoverController dismissPopoverAnimated:YES]; } }
  • 20. View Controllers DetailViewController.m - (void)configureView { NSString *currentNote = [[Data getAllNotes] objectForKey:[Data getCurrentKey]]; if (![currentNote isEqualToString:kDefaultText]) { self.tView.text = currentNote; } else { self.tView.text = @""; } [self.tView becomeFirstResponder]; }
  • 21. View Controllers DetailViewController.m - (void)viewWillDisappear:(BOOL)animated { if (![self.tView.text isEqualToString:@""]) { [Data setNoteForCurrentKey:self.tView.text]; } else { [Data removeNoteForKey:[Data getCurrentKey]]; } [Data saveNotes]; }
  • 23. View Controllers MasterViewController.m - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; NSDate *object = _objects[indexPath.row]; cell.textLabel.text = [[Data getAllNotes] objectForKey:[object description]]; return cell; }
  • 24. View Controllers MasterViewController.m - (void)makeObjects { _objects = [NSMutableArray arrayWithArray:[[Data getAllNotes] allKeys]]; [_objects sortUsingComparator:^NSComparisonResult(id obj1, id obj2) { return [(NSDate *)obj2 compare:(NSDate *)obj1]; }]; }
  • 25. View Controllers MasterViewController.m - (void)insertNewObject:(id)sender { [self makeObjects]; if (!_objects) { _objects = [[NSMutableArray alloc] init]; } //[_objects insertObject:[NSDate date] atIndex:0]; NSString *key = [[NSDate date] description]; [Data setNote:kDefaultText forKey:key]; [Data setCurrentKey:key]; [_objects insertObject:key atIndex:0]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; [self performSegueWithIdentifier:kDetailView sender:self]; }
  • 27. View Controllers MasterViewController.m - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { NSDate *object = _objects[indexPath.row]; self.detailViewController.detailItem = object; } } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"showDetail"]) { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; NSDate *object = _objects[indexPath.row]; [[segue destinationViewController] setDetailItem:object]; } }
  • 28. View Controllers MasterViewController.m - (void)viewWillAppear:(BOOL)animated { [super viewDidAppear:animated]; [self makeObjects]; [self.tableView reloadData]; }
  • 29. View Controllers MasterViewController.m - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [Data removeNoteForKey:[_objects objectAtIndex:indexPath.row]]; [Data saveNotes]; [_objects removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } }
  • 30. OVERVIEW • Lesson 1: Introductions • Lesson 2: iOS specifics • Lesson 3: Data Model • Lesson 4: Logic (Controller) & Interface