quick start to ios development
DESCRIPTION
TRANSCRIPT
![Page 1: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/1.jpg)
Quick Start to iOS Development
Jussi Pohjolainen Tampere University of Applied Sciences
![Page 2: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/2.jpg)
Anatomy?
![Page 3: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/3.jpg)
Anatomy
• Compiled Code, your's and framework's
• Nib – files: UI-‐elements • Resources: images, sounds, strings
• Info.plist – file: app configuraIon
![Page 4: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/4.jpg)
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>
![Page 5: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/5.jpg)
Info.plist in Xcode
![Page 6: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/6.jpg)
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
![Page 7: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/7.jpg)
nib-‐file
![Page 8: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/8.jpg)
nib – files in Interface Builder
![Page 9: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/9.jpg)
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; }
![Page 10: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/10.jpg)
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
![Page 11: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/11.jpg)
Life Cycle
![Page 12: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/12.jpg)
Design PaYern: DelegaIon
• One object sends periodically messages to another object specified as its delegate
• Delegate methods are grouped together with protocol (Java: Interface)
![Page 13: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/13.jpg)
Delegate?
• Xcode project template has provided UIApplicaIonDelegate for you
• Can implement: - applicationDidFinishLaunching
- applicationWillTerminate – applicationDidReceiveMemoryWarning – ...
![Page 14: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/14.jpg)
Delegate-‐class in Hello World
HelloWorldAppDelegate
IBOutlet UIWindow* window;
- applicationDidFinishLaunching - applicationWillTerminate - applicationDidReceiveMemoryWarning - ... - dealloc
NSObject
UIApplicationDelegate
![Page 15: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/15.jpg)
Delegate #import <UIKit/UIKit.h> @interface HelloWorldAppDelegate : NSObject
<UIApplicationDelegate> { UIWindow *window; } @property (nonatomic, retain) IBOutlet UIWindow
*window; @end
What is this?
![Page 16: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/16.jpg)
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.
![Page 17: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/17.jpg)
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
![Page 18: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/18.jpg)
Windows, Views
• iPhone app has usually one UIWindow • UIWindow can consist of UIViews. View can contain another UIViews (UI-‐elements)
• UIWindow – UIView • NSBuYon
![Page 19: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/19.jpg)
Interface Builder
![Page 20: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/20.jpg)
Interface Builder
![Page 21: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/21.jpg)
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
![Page 22: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/22.jpg)
Connect the Outlet with Interface Builder
![Page 23: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/23.jpg)
AcIons
• AcIons: what method is called when something happens?
![Page 24: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/24.jpg)
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
![Page 25: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/25.jpg)
In Interface Builder
![Page 26: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/26.jpg)
In Code #import "HelloWorldAppDelegate.h"
@implementation HelloWorldAppDelegate
@synthesize window;
@synthesize mytextfield;
- (IBAction) userClicked: (id) sender
{
NSString* text = [mytextfield text];
NSLog(text);
}
...
![Page 27: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/27.jpg)
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];
}
...
![Page 28: Quick Start to iOS Development](https://reader031.vdocuments.us/reader031/viewer/2022020206/546fd5f1b4af9ff5638b464a/html5/thumbnails/28.jpg)
Result