SlideShare ist ein Scribd-Unternehmen logo
1 von 23
iOS Development (Part II)
COMPILED BY: ASIM RAIS SIDDIQUI
Goals of the Lecture
 Use of TextField, Label, Sliders and Switch buttons
 Handling ActionSheet and Alerts
 Application Delegates
 Handling ActionSheet and Alerts
 Application Delegates
 UIApplication Delegates
 View Controllers
 Life Cycle of Application & Methods
 ARC
Application Delegate
 A delegate is an object that acts on behalf of, or in coordination
with, another object when that object encounters an event in a
program. The delegating object is often a responder object—that is,
an object inheriting from NSResponder in AppKit or UIResponder in
UIKit—that is responding to a user event. The delegate is an object
that is delegated control of the user interface for that event, or is at
least asked to interpret the event in an application-specific manner.
 These objects are designed to fulfill a specific role in a generic
fashion; a window object in the AppKit framework, for example,
responds to mouse manipulations of its controls and handles such
things as closing, resizing, and moving the physical window.
UIApplication & Delegates
View Controllers
View controllers are a vital link
between an app’s data and its visual
appearance. Whenever an iOS app
displays a user interface, the
displayed content is managed by a
view controller or a group of view
controllers coordinating with each
other. Therefore, view controllers
provide the skeletal framework on
which you build your apps.
iOS provides many built-in view
controller classes to support standard
user interface pieces, such as
navigation and tab bars. As part of
developing an app, you also
implement one or more custom
controllers to display the content
specific to your app.
Life Cycle &
Methods
Note:
 When Apple switched the default compiler from GCC to LLVM
recently, it stopped being necessary to declare instance variables
for properties. If LLVM finds a property without a matching instance
variable, it will create one automatically.
ARC
 Automatic Reference Counting (ARC) is a new feature of the
Objective-C language, introduced with iOS 5, that makes your life
much easier.
 It’s no longer necessary to release objects. Well, that’s not entirely true.
It is necessary, but the LLVM 3.0 compiler that Apple started shipping
with iOS 5 is so smart that it will release objects for us, using a new
feature called Automatic Reference Counting, or ARC, to do the heavy
lifting. That means no more dealloc methods, and no more worrying
about calling release or autorelease.
 ARC is very cool, but it’s not magic. You should still understand the basic
rules of memory management in Objective-C to avoid getting in
trouble with ARC. To brush up on the Objective-C memory
management contract, read Apple’s Memory Management
Programming Guide at this URL:
 https://developer.apple.com/library/ios/#documentation/Cocoa/Con
cep tual/MemoryMgmt/
Subclassing
 It is an important feature of any object-oriented programming
environment and the iPhone SDK is no exception to this rule. Subclassing
allows us to create a new class by deriving from an existing class and then
extending the functionality. In so doing we get all the functionality of the
parent class combined with the ability to extend the new class with
additional methods and properties.
Subclassing
@interface Superclass : NSObject {
int v;
}
- (void)initV;
@end
@implementation Superclass
- (void)initV {
v = 20;
}
@end
@interface Subclass : Superclass {
int w;
}
- (void)displayVars;
@end
@implementation Subclass
- (void)initW {
w = 50;
}
- (void)displayVars {
NSLog(@"v is %d, w is %d", v, w);
}
@end
Subclassing
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Subclass *sub = [[Subclass alloc] init];
[sub initV]; // Inherited method & ivar
[sub initW]; // Own method & ivar
[sub displayVars];// Inherited method [sub release];
[pool drain];
return 0;
}
Output:
v is 20, w is 50
Action Sheet and Alert
 Action sheets are used to force the user to make a choice between
two or more items. The action sheet comes up from the bottom of
the screen and displays a series of buttons. Users are unable to
continue using the application until they have tapped one of the
buttons. Action sheets are often used to confirm a potentially
dangerous or irreversible action such as deleting an object.
 Alerts appear as a blue, rounded rectangle in the middle of the
screen. Just like action sheets, alerts force users to respond before
they are allowed to continue using the application. Alerts are usually
used to inform the user that something important or out of the
ordinary has occurred. Unlike action sheets, alerts may be
presented with only a single button, although you have the option
of presenting multiple buttons if more than one response is
appropriate.
Conforming to the Action Sheet
Delegate Method
 In order for our controller class to act as the delegate for an action
sheet, it needs to conform to a protocol called
UIActionSheetDelegate.
 @interface BIDViewController : UIViewController
<UIActionSheetDelegate>
 Other parameter allow you to add more buttons
 E.g otherButtonTitles:@"Foo", @"Bar", nil
Switching Views
 presentModalViewController and presentViewController
 Other different techniques to switch views
 - view overlapping
 - navigation controller
Navigation Controller
 The main tool you’ll use to build hierarchical applications
is UINavigationController. UINavigationController is similar
to UITabBarController in that it manages, and swaps in
and out, multiple content views. The main difference
between the two is that UINavigationController is
implemented as a stack, which makes it well suited to
working with hierarchies.
 A stack is a commonly used data structure that works on
the principle of last in, first out.
Stack
 A computer stack follows the same rules:
 When you add an object to a stack, it’s called a push. You push an
object onto the stack.
 The first object you push onto the stack is called the base of the
stack.
 The last object you pushed onto the stack is called the top of the
stack
 (at least until it is replaced by the next object you push onto the stack).
 When you remove an object from the stack, it’s called a pop.
When you pop an object off the stack, it’s always the last one you
pushed onto the stack. Conversely, the first object you push onto the
stack will always be the last one you pop off the stack.
Setting Up the Navigation Controller
 Add property in main app delegate file
@property (strong, nonatomic) UINavigationController *navController;
Then implement
self.navController = [[UINavigationController alloc]
initWithRootViewController:self.viewController];
User push or pop, when needed:
[self.navigationController pushViewController:foo animated:YES];
TableViews
 First, what’s a Table View in iPhone app? Table View is one of the
common UI elements in iOS apps. Most apps, in some ways, make
use of Table View to display list of data.
 The best example is the built-in Phone app. Your contacts are
displayed in a Table View.
 Another example is the Mail app. It uses Table View to display your
mail boxes and emails. Not only designed for showing textual data,
Table View allows you to present the data in the form of images. The
built-in Video and YouTube app are great examples for the usage.
UITableViewDelegate and
UITableViewDataSource
 The UITableView, the actual class behind the Table View, is designed to be
flexible to handle various types of data. You may display a list of countries or
contact names. Or like this example, we’ll use the table view to present a list of
recipes. So how do you tell UITableView the list of data to display?
UITableViewDataSource is the answer. It’s the link between your data and the
table view. The UITableViewDataSource protocol declares two required
methods (tableView:cellForRowAtIndexPath and
tableView:numberOfRowsInSection) that you have to implement. Through
implementing these methods, you tell Table View how many rows to display and
the data in each row.
 UITableViewDelegate, on the other hand, deals with the appearance of the
UITableView. Optional methods of the protocols let you manage the height of a
table row, configure section headings and footers, re-order table cells, etc. We
do not change any of these methods in this example. Let’s leave them for the
next tutorial.
 numberOfSectionsInTableView
 numberOfRowsInSection
 cellForRowAtIndexPath
 didSelectRowAtIndexPath
Tab Bar App
 No more windows.xib file
 Add ThirdViewController subclassing UIViewController
 Add DetailViewController subclassing UIViewController
 #import "ThirdViewController.h"
 Create new class object
 ThirdViewController *navController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
 Create Navigation instance
 UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:navController];
@class Directive
 The @class directive sets up a forward reference to another class. It
tells the compiler that the named class exists, so when the compiler
gets to, say an @property directive line, no additional information is
needed, it assumes all is well and plows ahead.
@Classs
Vs
#Import

Weitere ähnliche Inhalte

Was ist angesagt?

Android appwidget
Android appwidgetAndroid appwidget
Android appwidgetKrazy Koder
 
Chapter 2 lesson-1 adding the action bar
Chapter 2 lesson-1 adding the action barChapter 2 lesson-1 adding the action bar
Chapter 2 lesson-1 adding the action barKalluri Vinay Reddy
 
Chapter 2 lesson-2 styling the action bar
Chapter 2 lesson-2 styling the action barChapter 2 lesson-2 styling the action bar
Chapter 2 lesson-2 styling the action barKalluri Vinay Reddy
 
Dive into Angular, part 3: Performance
Dive into Angular, part 3: PerformanceDive into Angular, part 3: Performance
Dive into Angular, part 3: PerformanceOleksii Prohonnyi
 
Android Screen Containers & Layouts
Android Screen Containers & LayoutsAndroid Screen Containers & Layouts
Android Screen Containers & LayoutsVijay Rastogi
 
Tools and practices for rapid application development
Tools and practices for rapid application developmentTools and practices for rapid application development
Tools and practices for rapid application developmentZoltán Váradi
 
Android Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetAndroid Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetPrajyot Mainkar
 
Angular JS, steal the idea
Angular JS, steal the ideaAngular JS, steal the idea
Angular JS, steal the ideaScott Lee
 
UI5con 2017 - Create your own UI5 controls – what’s coming up
UI5con 2017 - Create your own UI5 controls – what’s coming upUI5con 2017 - Create your own UI5 controls – what’s coming up
UI5con 2017 - Create your own UI5 controls – what’s coming upAndreas Kunz
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentalsAmr Salman
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to AngularjsGaurav Agrawal
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) PresentationRaghubir Singh
 
Create your own control - UI5Con
Create your own control - UI5ConCreate your own control - UI5Con
Create your own control - UI5ConWouter Lemaire
 
Binding,context mapping,navigation exercise
Binding,context mapping,navigation exerciseBinding,context mapping,navigation exercise
Binding,context mapping,navigation exerciseKranthi Kumar
 
Learnings for Accessibility for iOS Platform
Learnings for Accessibility for iOS PlatformLearnings for Accessibility for iOS Platform
Learnings for Accessibility for iOS PlatformTasneem Sayeed
 

Was ist angesagt? (20)

Android appwidget
Android appwidgetAndroid appwidget
Android appwidget
 
Chapter 2 lesson-1 adding the action bar
Chapter 2 lesson-1 adding the action barChapter 2 lesson-1 adding the action bar
Chapter 2 lesson-1 adding the action bar
 
Chapter 2 lesson-2 styling the action bar
Chapter 2 lesson-2 styling the action barChapter 2 lesson-2 styling the action bar
Chapter 2 lesson-2 styling the action bar
 
Dive into Angular, part 3: Performance
Dive into Angular, part 3: PerformanceDive into Angular, part 3: Performance
Dive into Angular, part 3: Performance
 
Android Screen Containers & Layouts
Android Screen Containers & LayoutsAndroid Screen Containers & Layouts
Android Screen Containers & Layouts
 
Android course (lecture2)
Android course (lecture2)Android course (lecture2)
Android course (lecture2)
 
Calc app
Calc appCalc app
Calc app
 
Android xml-based layouts-chapter5
Android xml-based layouts-chapter5Android xml-based layouts-chapter5
Android xml-based layouts-chapter5
 
Tools and practices for rapid application development
Tools and practices for rapid application developmentTools and practices for rapid application development
Tools and practices for rapid application development
 
Android Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetAndroid Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection Widget
 
Les16
Les16Les16
Les16
 
Angular JS, steal the idea
Angular JS, steal the ideaAngular JS, steal the idea
Angular JS, steal the idea
 
SharePoint Framework y React
SharePoint Framework y ReactSharePoint Framework y React
SharePoint Framework y React
 
UI5con 2017 - Create your own UI5 controls – what’s coming up
UI5con 2017 - Create your own UI5 controls – what’s coming upUI5con 2017 - Create your own UI5 controls – what’s coming up
UI5con 2017 - Create your own UI5 controls – what’s coming up
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentals
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) Presentation
 
Create your own control - UI5Con
Create your own control - UI5ConCreate your own control - UI5Con
Create your own control - UI5Con
 
Binding,context mapping,navigation exercise
Binding,context mapping,navigation exerciseBinding,context mapping,navigation exercise
Binding,context mapping,navigation exercise
 
Learnings for Accessibility for iOS Platform
Learnings for Accessibility for iOS PlatformLearnings for Accessibility for iOS Platform
Learnings for Accessibility for iOS Platform
 

Ähnlich wie iOS Development (Part 2)

Ähnlich wie iOS Development (Part 2) (20)

Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Swift
SwiftSwift
Swift
 
ANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.doc
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
Java lab lecture 2
Java  lab  lecture 2Java  lab  lecture 2
Java lab lecture 2
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Hello Android
Hello AndroidHello Android
Hello Android
 
Advanced java lab swing mvc awt
Advanced java lab swing mvc awtAdvanced java lab swing mvc awt
Advanced java lab swing mvc awt
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Intro to ios - init by SLOHacks
Intro to ios - init by SLOHacksIntro to ios - init by SLOHacks
Intro to ios - init by SLOHacks
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid draw
 
UIAutomator
UIAutomatorUIAutomator
UIAutomator
 
Ch12. graphical user interfaces
Ch12. graphical user interfacesCh12. graphical user interfaces
Ch12. graphical user interfaces
 
Csharp
CsharpCsharp
Csharp
 
android activity
android activityandroid activity
android activity
 

Mehr von Asim Rais Siddiqui

Understanding Blockchain Technology
Understanding Blockchain TechnologyUnderstanding Blockchain Technology
Understanding Blockchain TechnologyAsim Rais Siddiqui
 
IoT Development - Opportunities and Challenges
IoT Development - Opportunities and ChallengesIoT Development - Opportunities and Challenges
IoT Development - Opportunities and ChallengesAsim Rais Siddiqui
 
iOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI ComponentsiOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI ComponentsAsim Rais Siddiqui
 
Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Asim Rais Siddiqui
 
Introduction to iOS Development
Introduction to iOS DevelopmentIntroduction to iOS Development
Introduction to iOS DevelopmentAsim Rais Siddiqui
 

Mehr von Asim Rais Siddiqui (8)

Understanding Blockchain Technology
Understanding Blockchain TechnologyUnderstanding Blockchain Technology
Understanding Blockchain Technology
 
IoT Development - Opportunities and Challenges
IoT Development - Opportunities and ChallengesIoT Development - Opportunities and Challenges
IoT Development - Opportunities and Challenges
 
iOS Memory Management
iOS Memory ManagementiOS Memory Management
iOS Memory Management
 
iOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI ComponentsiOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI Components
 
iOS Development (Part 1)
iOS Development (Part 1)iOS Development (Part 1)
iOS Development (Part 1)
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 
Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#
 
Introduction to iOS Development
Introduction to iOS DevelopmentIntroduction to iOS Development
Introduction to iOS Development
 

Kürzlich hochgeladen

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Kürzlich hochgeladen (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

iOS Development (Part 2)

  • 1. iOS Development (Part II) COMPILED BY: ASIM RAIS SIDDIQUI
  • 2. Goals of the Lecture  Use of TextField, Label, Sliders and Switch buttons  Handling ActionSheet and Alerts  Application Delegates  Handling ActionSheet and Alerts  Application Delegates  UIApplication Delegates  View Controllers  Life Cycle of Application & Methods  ARC
  • 3. Application Delegate  A delegate is an object that acts on behalf of, or in coordination with, another object when that object encounters an event in a program. The delegating object is often a responder object—that is, an object inheriting from NSResponder in AppKit or UIResponder in UIKit—that is responding to a user event. The delegate is an object that is delegated control of the user interface for that event, or is at least asked to interpret the event in an application-specific manner.  These objects are designed to fulfill a specific role in a generic fashion; a window object in the AppKit framework, for example, responds to mouse manipulations of its controls and handles such things as closing, resizing, and moving the physical window.
  • 5. View Controllers View controllers are a vital link between an app’s data and its visual appearance. Whenever an iOS app displays a user interface, the displayed content is managed by a view controller or a group of view controllers coordinating with each other. Therefore, view controllers provide the skeletal framework on which you build your apps. iOS provides many built-in view controller classes to support standard user interface pieces, such as navigation and tab bars. As part of developing an app, you also implement one or more custom controllers to display the content specific to your app.
  • 7. Note:  When Apple switched the default compiler from GCC to LLVM recently, it stopped being necessary to declare instance variables for properties. If LLVM finds a property without a matching instance variable, it will create one automatically.
  • 8. ARC  Automatic Reference Counting (ARC) is a new feature of the Objective-C language, introduced with iOS 5, that makes your life much easier.  It’s no longer necessary to release objects. Well, that’s not entirely true. It is necessary, but the LLVM 3.0 compiler that Apple started shipping with iOS 5 is so smart that it will release objects for us, using a new feature called Automatic Reference Counting, or ARC, to do the heavy lifting. That means no more dealloc methods, and no more worrying about calling release or autorelease.  ARC is very cool, but it’s not magic. You should still understand the basic rules of memory management in Objective-C to avoid getting in trouble with ARC. To brush up on the Objective-C memory management contract, read Apple’s Memory Management Programming Guide at this URL:  https://developer.apple.com/library/ios/#documentation/Cocoa/Con cep tual/MemoryMgmt/
  • 9. Subclassing  It is an important feature of any object-oriented programming environment and the iPhone SDK is no exception to this rule. Subclassing allows us to create a new class by deriving from an existing class and then extending the functionality. In so doing we get all the functionality of the parent class combined with the ability to extend the new class with additional methods and properties.
  • 10. Subclassing @interface Superclass : NSObject { int v; } - (void)initV; @end @implementation Superclass - (void)initV { v = 20; } @end @interface Subclass : Superclass { int w; } - (void)displayVars; @end @implementation Subclass - (void)initW { w = 50; } - (void)displayVars { NSLog(@"v is %d, w is %d", v, w); } @end
  • 11. Subclassing int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; Subclass *sub = [[Subclass alloc] init]; [sub initV]; // Inherited method & ivar [sub initW]; // Own method & ivar [sub displayVars];// Inherited method [sub release]; [pool drain]; return 0; } Output: v is 20, w is 50
  • 12. Action Sheet and Alert  Action sheets are used to force the user to make a choice between two or more items. The action sheet comes up from the bottom of the screen and displays a series of buttons. Users are unable to continue using the application until they have tapped one of the buttons. Action sheets are often used to confirm a potentially dangerous or irreversible action such as deleting an object.  Alerts appear as a blue, rounded rectangle in the middle of the screen. Just like action sheets, alerts force users to respond before they are allowed to continue using the application. Alerts are usually used to inform the user that something important or out of the ordinary has occurred. Unlike action sheets, alerts may be presented with only a single button, although you have the option of presenting multiple buttons if more than one response is appropriate.
  • 13. Conforming to the Action Sheet Delegate Method  In order for our controller class to act as the delegate for an action sheet, it needs to conform to a protocol called UIActionSheetDelegate.  @interface BIDViewController : UIViewController <UIActionSheetDelegate>  Other parameter allow you to add more buttons  E.g otherButtonTitles:@"Foo", @"Bar", nil
  • 14. Switching Views  presentModalViewController and presentViewController  Other different techniques to switch views  - view overlapping  - navigation controller
  • 15. Navigation Controller  The main tool you’ll use to build hierarchical applications is UINavigationController. UINavigationController is similar to UITabBarController in that it manages, and swaps in and out, multiple content views. The main difference between the two is that UINavigationController is implemented as a stack, which makes it well suited to working with hierarchies.  A stack is a commonly used data structure that works on the principle of last in, first out.
  • 16. Stack  A computer stack follows the same rules:  When you add an object to a stack, it’s called a push. You push an object onto the stack.  The first object you push onto the stack is called the base of the stack.  The last object you pushed onto the stack is called the top of the stack  (at least until it is replaced by the next object you push onto the stack).  When you remove an object from the stack, it’s called a pop. When you pop an object off the stack, it’s always the last one you pushed onto the stack. Conversely, the first object you push onto the stack will always be the last one you pop off the stack.
  • 17. Setting Up the Navigation Controller  Add property in main app delegate file @property (strong, nonatomic) UINavigationController *navController; Then implement self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController]; User push or pop, when needed: [self.navigationController pushViewController:foo animated:YES];
  • 18. TableViews  First, what’s a Table View in iPhone app? Table View is one of the common UI elements in iOS apps. Most apps, in some ways, make use of Table View to display list of data.  The best example is the built-in Phone app. Your contacts are displayed in a Table View.  Another example is the Mail app. It uses Table View to display your mail boxes and emails. Not only designed for showing textual data, Table View allows you to present the data in the form of images. The built-in Video and YouTube app are great examples for the usage.
  • 19. UITableViewDelegate and UITableViewDataSource  The UITableView, the actual class behind the Table View, is designed to be flexible to handle various types of data. You may display a list of countries or contact names. Or like this example, we’ll use the table view to present a list of recipes. So how do you tell UITableView the list of data to display? UITableViewDataSource is the answer. It’s the link between your data and the table view. The UITableViewDataSource protocol declares two required methods (tableView:cellForRowAtIndexPath and tableView:numberOfRowsInSection) that you have to implement. Through implementing these methods, you tell Table View how many rows to display and the data in each row.  UITableViewDelegate, on the other hand, deals with the appearance of the UITableView. Optional methods of the protocols let you manage the height of a table row, configure section headings and footers, re-order table cells, etc. We do not change any of these methods in this example. Let’s leave them for the next tutorial.
  • 20.  numberOfSectionsInTableView  numberOfRowsInSection  cellForRowAtIndexPath  didSelectRowAtIndexPath
  • 21. Tab Bar App  No more windows.xib file  Add ThirdViewController subclassing UIViewController  Add DetailViewController subclassing UIViewController  #import "ThirdViewController.h"  Create new class object  ThirdViewController *navController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];  Create Navigation instance  UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:navController];
  • 22. @class Directive  The @class directive sets up a forward reference to another class. It tells the compiler that the named class exists, so when the compiler gets to, say an @property directive line, no additional information is needed, it assumes all is well and plows ahead.

Hinweis der Redaktion

  1. It is an important feature of any object-oriented programming environment and the iPhone SDK is no exception to this rule. Subclassing allows us to create a new class by deriving from an existing class and then extending the functionality. In so doing we get all the functionality of the parent class combined with the ability to extend the new class with additional methods and properties.Subclassing is typically used where an existing class exists that does most, but not all, of what you need. By subclassing we get all that existing functionality without having to duplicate it and simply add on the functionality that was missing.We will see an example of subclassing in the context of iPhone development when we start to work with view controllers. The UIKit framework contains a class called the UIViewController. This is a generic view controller from which we will create a subclass so that we can add our own methods and properties.
  2. The next argument is the delegate for the action sheet. The action sheet’s delegate will be notified when a button on that sheet has been tapped. More specifically, the delegate’s actionSheet:didDismissWithButtonIndex: method will be called. By passing self as the delegate parameter, we ensure that our version of actionSheet:didDismissWithButtonIndex: will be called. Why didn’t we just use view, instead of self.view? view is a private instance variable of our parent class UIViewController, which means we can’t access it directly, but instead must use an accessor method.
  3. @class doesn&apos;t import the file, it just says to the compiler &quot;This class exists even though you don&apos;t know about it, don&apos;t warn me if I use it&quot;. #import actually imports the file so you can use all the methods and instance variables. @class is used to save time compiling (importing the whole file makes the compile take more time). You can use #import if you want, it will just take longer for your project to build.