Quick Start to iOS Development
-
Upload
jussi-pohjolainen -
Category
Technology
-
view
5.416 -
download
2
description
Transcript of Quick Start to iOS Development
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
HelloWorldAppDelegate
IBOutlet UIWindow* window;
- applicationDidFinishLaunching - applicationWillTerminate - applicationDidReceiveMemoryWarning - ... - dealloc
NSObject
UIApplicationDelegate
Delegate #import <UIKit/UIKit.h> @interface HelloWorldAppDelegate : NSObject
<UIApplicationDelegate> { UIWindow *window; } @property (nonatomic, retain) IBOutlet UIWindow
*window; @end
What is this?
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