SlideShare uma empresa Scribd logo
1 de 28
Baixar para ler offline
Quick	
  Start	
  to	
  iOS	
  Development	
  

                Jussi	
  Pohjolainen	
  
    Tampere	
  University	
  of	
  Applied	
  Sciences	
  
Anatomy?	
  
Anatomy	
  
•  Compiled	
  Code,	
  your's	
  
   and	
  framework's	
  
•  Nib	
  –	
  files:	
  UI-­‐elements	
  
•  Resources:	
  images,	
  
   sounds,	
  strings	
  
•  Info.plist	
  –	
  file:	
  app	
  
   configuraIon	
  	
  
info.plist	
  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
       <key>CFBundleDevelopmentRegion</key>
       <string>English</string>
       <key>CFBundleDisplayName</key>
       <string>${PRODUCT_NAME}</string>
       <key>CFBundleExecutable</key>
       <string>${EXECUTABLE_NAME}</string>
       <key>CFBundleIconFile</key>
       <string></string>
       <key>CFBundleIdentifier</key>
       <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
       <key>CFBundleInfoDictionaryVersion</key>
       <string>6.0</string>
       <key>CFBundleName</key>
       <string>${PRODUCT_NAME}</string>
       <key>CFBundlePackageType</key>
       <string>APPL</string>
       <key>CFBundleSignature</key>
       <string>????</string>
       <key>CFBundleVersion</key>
       <string>1.0</string>
       <key>LSRequiresIPhoneOS</key>
       <true/>
       <key>NSMainNibFile</key>
       <string>MainWindow</string>
</dict>
</plist>
Info.plist	
  in	
  Xcode	
  
nib-­‐file?	
  
•  Interface	
  Builder	
  is	
  used	
  for	
  creaIng	
  Uis	
  
•  The	
  interface	
  is	
  stored	
  in	
  a	
  file	
  .n/xib	
  
    –  .nib	
  =	
  Next	
  Interface	
  Builder	
  
    –  .xib	
  =	
  new	
  version	
  (Interface	
  Builder	
  3)	
  of	
  nib	
  
•  The	
  xib	
  file	
  is	
  xml!	
  
•  By	
  conven)on,	
  refer	
  to	
  nib	
  
nib-­‐file	
  
nib	
  –	
  files	
  in	
  Interface	
  Builder	
  
main.m	
  
//
//   main.m
//   ExampleOfiPhoneApp
//
//   Created by Jussi Pohjolainen on 22.3.2010.
//   Copyright TAMK 2010. All rights reserved.
//

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {

     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
     int retVal = UIApplicationMain(argc, argv, nil, nil);
     [pool release];
     return retVal;
}
UIApplicaIonMain?	
  
•  Creates	
  instance	
  of	
  UIApplicaIon	
  
•  Scans	
  info.plist	
  
•  Opens	
  the	
  UI	
  –	
  file	
  (xib)	
  that	
  is	
  defined	
  in	
  
     info.plist	
  (mainwindow.xib)	
  
•  Connects	
  to	
  window	
  server	
  
•  Establishes	
  run	
  loop	
  
•  Calls	
  method's	
  from	
  it's	
  delegate	
  
	
  
Life	
  Cycle	
  
Design	
  PaYern:	
  DelegaIon	
  
•  One	
  object	
  sends	
  periodically	
  messages	
  to	
  
   another	
  object	
  specified	
  as	
  its	
  delegate	
  
•  Delegate	
  methods	
  are	
  grouped	
  together	
  with	
  
   protocol	
  (Java:	
  Interface)	
  
Delegate?	
  
•  Xcode	
  project	
  template	
  has	
  provided	
  
   UIApplicaIonDelegate	
  for	
  you	
  
•  Can	
  implement:	
  
   - applicationDidFinishLaunching
   -  applicationWillTerminate
   –  applicationDidReceiveMemoryWarning
   –  ...
Delegate-­‐class	
  in	
  Hello	
  World	
  
                        NSObject



                        HelloWorldAppDelegate
                        IBOutlet UIWindow* window;

UIApplicationDelegate
                        -    applicationDidFinishLaunching
                        -    applicationWillTerminate
                        -    applicationDidReceiveMemoryWarning
                        -    ...
                        -    dealloc
Delegate	
  
#import <UIKit/UIKit.h>

@interface HelloWorldAppDelegate : NSObject
  <UIApplicationDelegate> {
    UIWindow *window;
}                                What	
  is	
  
                                    this?	
  

@property (nonatomic, retain) IBOutlet UIWindow
  *window;

@end
Outlet?	
  
•  Outlet:	
  the	
  UI	
  widget	
  is	
  implemented	
  in	
  
   Interface	
  Builder!	
  
•  When	
  the	
  app	
  starts,	
  the	
  main	
  .nib	
  file	
  is	
  
   loaded	
  
       –  MainWindow.xib	
  
•  This	
  file	
  contains	
  UIWindow	
  that	
  can	
  be	
  
   modified	
  via	
  the	
  Interface	
  Builder.	
  

	
  
Delegate	
  classes	
  implementaIon	
  
#import "HelloWorldAppDelegate.h"

@implementation HelloWorldAppDelegate

@synthesize window;


- (void)applicationDidFinishLaunching:(UIApplication *)application {

    // Override point for customization after application launch
    [window makeKeyAndVisible];
}


- (void)dealloc {
    [window release];
    [super dealloc];
}


@end
Windows,	
  Views	
  
•  iPhone	
  app	
  has	
  usually	
  one	
  UIWindow	
  
•  UIWindow	
  can	
  consist	
  of	
  UIViews.	
  View	
  can	
  
   contain	
  another	
  UIViews	
  (UI-­‐elements)	
  
•  UIWindow	
  
   –  UIView	
  
       •  NSBuYon	
  
Interface	
  Builder	
  
Interface	
  Builder	
  
In	
  Code	
  
#import <UIKit/UIKit.h>

@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UITextField *mytextfield;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITextField *mytextfield;

@end
Connect	
  the	
  Outlet	
  with	
  Interface	
  
                  Builder	
  
AcIons	
  
•  AcIons:	
  what	
  method	
  is	
  called	
  when	
  
     something	
  happens?	
  
	
  
In	
  Code	
  
#import <UIKit/UIKit.h>

@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UITextField *mytextfield;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITextField *mytextfield;

-  (IBAction) userClicked: (id) sender;

@end
In	
  Interface	
  Builder	
  
In	
  Code	
  
#import "HelloWorldAppDelegate.h"

@implementation HelloWorldAppDelegate

@synthesize window;
@synthesize mytextfield;

- (IBAction) userClicked: (id) sender
{
    NSString* text = [mytextfield text];
    NSLog(text);
}
...
In	
  Code:	
  Using	
  Alert	
  
#import "HelloWorldAppDelegate.h"

@implementation HelloWorldAppDelegate

@synthesize window;
@synthesize mytextfield;

- (IBAction) userClicked: (id) sender
{
    NSString* text = [mytextfield text];
    UIAlertView *alert   = [[UIAlertView alloc]
                            initWithTitle:@"Hello"
                            message:text
                            delegate:nil
                            cancelButtonTitle:@"Ok"
                            otherButtonTitles:nil];
    [alert show];
    [alert release];
}
...
Result	
  

Mais conteúdo relacionado

Mais procurados

Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDE
Benjamin Cabé
 

Mais procurados (20)

Angular js 2
Angular js 2Angular js 2
Angular js 2
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Design Patterns in XCUITest
Design Patterns in XCUITestDesign Patterns in XCUITest
Design Patterns in XCUITest
 
XCUITest for iOS App Testing and how to test with Xcode
XCUITest for iOS App Testing and how to test with XcodeXCUITest for iOS App Testing and how to test with Xcode
XCUITest for iOS App Testing and how to test with Xcode
 
CDI: How do I ?
CDI: How do I ?CDI: How do I ?
CDI: How do I ?
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
 
I os 11
I os 11I os 11
I os 11
 
Angularjs
AngularjsAngularjs
Angularjs
 
Testing iOS10 Apps with Appium and its new XCUITest backend
Testing iOS10 Apps with Appium and its new XCUITest backendTesting iOS10 Apps with Appium and its new XCUITest backend
Testing iOS10 Apps with Appium and its new XCUITest backend
 
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
 
AngularJs
AngularJsAngularJs
AngularJs
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
Speed up your GWT coding with gQuery
Speed up your GWT coding with gQuerySpeed up your GWT coding with gQuery
Speed up your GWT coding with gQuery
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDE
 
AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0
 
Android development with Scala and SBT
Android development with Scala and SBTAndroid development with Scala and SBT
Android development with Scala and SBT
 

Destaque

Destaque (11)

iOS Apps for Learning - BLC2011
iOS Apps for Learning - BLC2011iOS Apps for Learning - BLC2011
iOS Apps for Learning - BLC2011
 
5 Realms for Learning iOS Development
5 Realms for Learning iOS Development5 Realms for Learning iOS Development
5 Realms for Learning iOS Development
 
Shortcut in learning iOS
Shortcut in learning iOSShortcut in learning iOS
Shortcut in learning iOS
 
How & where to start iOS development?
How & where to start iOS development?How & where to start iOS development?
How & where to start iOS development?
 
iOS Architecture and MVC
iOS Architecture and MVCiOS Architecture and MVC
iOS Architecture and MVC
 
iOS Introduction For Very Beginners
iOS Introduction For Very BeginnersiOS Introduction For Very Beginners
iOS Introduction For Very Beginners
 
Building iOS App Project & Architecture
Building iOS App Project & ArchitectureBuilding iOS App Project & Architecture
Building iOS App Project & Architecture
 
Basic Intro to iOS
Basic Intro to iOSBasic Intro to iOS
Basic Intro to iOS
 
iOS Coding Best Practices
iOS Coding Best PracticesiOS Coding Best Practices
iOS Coding Best Practices
 
Presentation on iOS
Presentation on iOSPresentation on iOS
Presentation on iOS
 
Architecting iOS Project
Architecting iOS ProjectArchitecting iOS Project
Architecting iOS Project
 

Semelhante a Quick Start to iOS Development

Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
Anh Quân
 
Baruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion WorkshopBaruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion Workshop
Brian Sam-Bodden
 

Semelhante a Quick Start to iOS Development (20)

iOS
iOSiOS
iOS
 
Ios - Introduction to platform & SDK
Ios - Introduction to platform & SDKIos - Introduction to platform & SDK
Ios - Introduction to platform & SDK
 
iPhone SDK dev sharing - the very basics
iPhone SDK dev sharing - the very basicsiPhone SDK dev sharing - the very basics
iPhone SDK dev sharing - the very basics
 
Leaving Interface Builder Behind
Leaving Interface Builder BehindLeaving Interface Builder Behind
Leaving Interface Builder Behind
 
A tour through Swift attributes
A tour through Swift attributesA tour through Swift attributes
A tour through Swift attributes
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
 
Building maintainable app #droidconzg
Building maintainable app #droidconzgBuilding maintainable app #droidconzg
Building maintainable app #droidconzg
 
Google GIN
Google GINGoogle GIN
Google GIN
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
 
JavaScript on the Desktop
JavaScript on the DesktopJavaScript on the Desktop
JavaScript on the Desktop
 
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
 
Building maintainable app
Building maintainable appBuilding maintainable app
Building maintainable app
 
New to native? Getting Started With iOS Development
New to native?   Getting Started With iOS DevelopmentNew to native?   Getting Started With iOS Development
New to native? Getting Started With iOS Development
 
NativeScript and Angular
NativeScript and AngularNativeScript and Angular
NativeScript and Angular
 
Baruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion WorkshopBaruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion Workshop
 
03 - Qt UI Development
03 - Qt UI Development03 - Qt UI Development
03 - Qt UI Development
 
Ignite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and FirebaseIgnite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and Firebase
 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una Daly
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
 

Mais de Jussi Pohjolainen

Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi 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 Gestures
Jussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
Jussi Pohjolainen
 

Mais de 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
 

Último

Último (20)

Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 

Quick Start to iOS Development

  • 1. Quick  Start  to  iOS  Development   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 3. Anatomy   •  Compiled  Code,  your's   and  framework's   •  Nib  –  files:  UI-­‐elements   •  Resources:  images,   sounds,  strings   •  Info.plist  –  file:  app   configuraIon    
  • 4. info.plist   <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleDisplayName</key> <string>${PRODUCT_NAME}</string> <key>CFBundleExecutable</key> <string>${EXECUTABLE_NAME}</string> <key>CFBundleIconFile</key> <string></string> <key>CFBundleIdentifier</key> <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>${PRODUCT_NAME}</string> <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>1.0</string> <key>LSRequiresIPhoneOS</key> <true/> <key>NSMainNibFile</key> <string>MainWindow</string> </dict> </plist>
  • 6. nib-­‐file?   •  Interface  Builder  is  used  for  creaIng  Uis   •  The  interface  is  stored  in  a  file  .n/xib   –  .nib  =  Next  Interface  Builder   –  .xib  =  new  version  (Interface  Builder  3)  of  nib   •  The  xib  file  is  xml!   •  By  conven)on,  refer  to  nib  
  • 8. nib  –  files  in  Interface  Builder  
  • 9. main.m   // // main.m // ExampleOfiPhoneApp // // Created by Jussi Pohjolainen on 22.3.2010. // Copyright TAMK 2010. All rights reserved. // #import <UIKit/UIKit.h> int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; }
  • 10. UIApplicaIonMain?   •  Creates  instance  of  UIApplicaIon   •  Scans  info.plist   •  Opens  the  UI  –  file  (xib)  that  is  defined  in   info.plist  (mainwindow.xib)   •  Connects  to  window  server   •  Establishes  run  loop   •  Calls  method's  from  it's  delegate    
  • 12. Design  PaYern:  DelegaIon   •  One  object  sends  periodically  messages  to   another  object  specified  as  its  delegate   •  Delegate  methods  are  grouped  together  with   protocol  (Java:  Interface)  
  • 13. Delegate?   •  Xcode  project  template  has  provided   UIApplicaIonDelegate  for  you   •  Can  implement:   - applicationDidFinishLaunching -  applicationWillTerminate –  applicationDidReceiveMemoryWarning –  ...
  • 14. Delegate-­‐class  in  Hello  World   NSObject HelloWorldAppDelegate IBOutlet UIWindow* window; UIApplicationDelegate -  applicationDidFinishLaunching -  applicationWillTerminate -  applicationDidReceiveMemoryWarning -  ... -  dealloc
  • 15. Delegate   #import <UIKit/UIKit.h> @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; } What  is   this?   @property (nonatomic, retain) IBOutlet UIWindow *window; @end
  • 16. Outlet?   •  Outlet:  the  UI  widget  is  implemented  in   Interface  Builder!   •  When  the  app  starts,  the  main  .nib  file  is   loaded   –  MainWindow.xib   •  This  file  contains  UIWindow  that  can  be   modified  via  the  Interface  Builder.    
  • 17. Delegate  classes  implementaIon   #import "HelloWorldAppDelegate.h" @implementation HelloWorldAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch [window makeKeyAndVisible]; } - (void)dealloc { [window release]; [super dealloc]; } @end
  • 18. Windows,  Views   •  iPhone  app  has  usually  one  UIWindow   •  UIWindow  can  consist  of  UIViews.  View  can   contain  another  UIViews  (UI-­‐elements)   •  UIWindow   –  UIView   •  NSBuYon  
  • 21. In  Code   #import <UIKit/UIKit.h> @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; UITextField *mytextfield; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITextField *mytextfield; @end
  • 22. Connect  the  Outlet  with  Interface   Builder  
  • 23. AcIons   •  AcIons:  what  method  is  called  when   something  happens?    
  • 24. In  Code   #import <UIKit/UIKit.h> @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; UITextField *mytextfield; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITextField *mytextfield; -  (IBAction) userClicked: (id) sender; @end
  • 26. In  Code   #import "HelloWorldAppDelegate.h" @implementation HelloWorldAppDelegate @synthesize window; @synthesize mytextfield; - (IBAction) userClicked: (id) sender { NSString* text = [mytextfield text]; NSLog(text); } ...
  • 27. In  Code:  Using  Alert   #import "HelloWorldAppDelegate.h" @implementation HelloWorldAppDelegate @synthesize window; @synthesize mytextfield; - (IBAction) userClicked: (id) sender { NSString* text = [mytextfield text]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:text delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; [alert release]; } ...