Intro	
  to	
  iPhone	
  Development	
  

              Jussi	
  Pohjolainen	
  
  Tampere	
  University	
  of	
  Applied	...
Anatomy?	
  
Anatomy	
  
•  Compiled	
  Code,	
  your's	
  
   and	
  framework's	
  
•  Nib	
  –	
  files:	
  UI-­‐elements	
  
•  Reso...
info.plist	
  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.app...
Info.plist	
  in	
  Xcode	
  
nib-­‐file?	
  
•  Interface	
  Builder	
  is	
  used	
  for	
  creaGng	
  Uis	
  
•  The	
  interface	
  is	
  stored	
  i...
nib-­‐file	
  
nib	
  –	
  files	
  in	
  Interface	
  Builder	
  
main.m	
  
//
//   main.m
//   ExampleOfiPhoneApp
//
//   Created by Jussi Pohjolainen on 22.3.2010.
//   Copyright TAMK 2...
UIApplicaGonMain?	
  
•  Creates	
  instance	
  of	
  UIApplicaGon	
  
•  Scans	
  info.plist	
  
•  Opens	
  the	
  UI	
 ...
Life	
  Cycle	
  
Design	
  PaXern:	
  DelegaGon	
  
•  One	
  object	
  sends	
  periodically	
  messages	
  to	
  
   another	
  object	
 ...
Delegate?	
  
•  Xcode	
  project	
  template	
  has	
  provided	
  
   UIApplicaGonDelegate	
  for	
  you	
  
•  Can	
  i...
Delegate-­‐class	
  in	
  Hello	
  World	
  
                        NSObject



                        HelloWorldAppDele...
Delegate	
  
#import <UIKit/UIKit.h>

@interface HelloWorldAppDelegate : NSObject
  <UIApplicationDelegate> {
    UIWindow...
Outlet?	
  
•  Outlet:	
  the	
  UI	
  widget	
  is	
  implemented	
  in	
  
   Interface	
  Builder!	
  
•  When	
  the	
...
Delegate	
  classes	
  implementaGon	
  
#import "HelloWorldAppDelegate.h"

@implementation HelloWorldAppDelegate

@synthe...
Windows,	
  Views	
  
•  iPhone	
  app	
  has	
  usually	
  one	
  UIWindow	
  
•  UIWindow	
  can	
  consist	
  of	
  UIV...
Interface	
  Builder	
  
Interface	
  Builder	
  
In	
  Code	
  
#import <UIKit/UIKit.h>

@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow...
Connect	
  the	
  Outlet	
  with	
  Interface	
  
                  Builder	
  
AcGons	
  
•  AcGons:	
  what	
  method	
  is	
  called	
  when	
  
   something	
  happens?	
  
In	
  Code	
  
#import <UIKit/UIKit.h>

@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow...
In	
  Interface	
  Builder	
  
In	
  Code	
  
#import "HelloWorldAppDelegate.h"

@implementation HelloWorldAppDelegate

@synthesize window;
@synthesize m...
In	
  Code:	
  Using	
  Alert	
  
#import "HelloWorldAppDelegate.h"

@implementation HelloWorldAppDelegate

@synthesize wi...
Result	
  
Upcoming SlideShare
Loading in …5
×

Quick Start to iOS Development

4,872 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,872
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
171
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Quick Start to iOS Development

  1. 1. Intro  to  iPhone  Development   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  2. 2. Anatomy?  
  3. 3. Anatomy   •  Compiled  Code,  your's   and  framework's   •  Nib  –  files:  UI-­‐elements   •  Resources:  images,   sounds,  strings   •  Info.plist  –  file:  app   configuraGon    
  4. 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>
  5. 5. Info.plist  in  Xcode  
  6. 6. nib-­‐file?   •  Interface  Builder  is  used  for  creaGng  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  
  7. 7. nib-­‐file  
  8. 8. nib  –  files  in  Interface  Builder  
  9. 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. 10. UIApplicaGonMain?   •  Creates  instance  of  UIApplicaGon   •  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  
  11. 11. Life  Cycle  
  12. 12. Design  PaXern:  DelegaGon   •  One  object  sends  periodically  messages  to   another  object  specified  as  its  delegate   •  Delegate  methods  are  grouped  together  with   protocol  (Java:  Interface)  
  13. 13. Delegate?   •  Xcode  project  template  has  provided   UIApplicaGonDelegate  for  you   •  Can  implement:   - applicationDidFinishLaunching -  applicationWillTerminate –  applicationDidReceiveMemoryWarning –  ...
  14. 14. Delegate-­‐class  in  Hello  World   NSObject HelloWorldAppDelegate IBOutlet UIWindow* window; UIApplicationDelegate -  applicationDidFinishLaunching -  applicationWillTerminate -  applicationDidReceiveMemoryWarning -  ... -  dealloc
  15. 15. Delegate   #import <UIKit/UIKit.h> @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; } What  is   this?   @property (nonatomic, retain) IBOutlet UIWindow *window; @end
  16. 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. 17. Delegate  classes  implementaGon   #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. 18. Windows,  Views   •  iPhone  app  has  usually  one  UIWindow   •  UIWindow  can  consist  of  UIViews.  View  can   contain  another  UIViews  (UI-­‐elements)   •  UIWindow   –  UIView   •  NSBuXon  
  19. 19. Interface  Builder  
  20. 20. Interface  Builder  
  21. 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. 22. Connect  the  Outlet  with  Interface   Builder  
  23. 23. AcGons   •  AcGons:  what  method  is  called  when   something  happens?  
  24. 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
  25. 25. In  Interface  Builder  
  26. 26. In  Code   #import "HelloWorldAppDelegate.h" @implementation HelloWorldAppDelegate @synthesize window; @synthesize mytextfield; - (IBAction) userClicked: (id) sender { NSString* text = [mytextfield text]; NSLog(text); } ...
  27. 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]; } ...
  28. 28. Result  

×