SlideShare a Scribd company logo
iPhone
         Objective-C, UIKit




                              bofeng@corp.netease.com
                                             @vonbo
Agenda

• overview
• objective-c
• iPhone UIKit
overview
First iPhone App


• Hello world!
Things we have



• Hello world!
• xcode SDK
•       & test with Simulator

• test with iPhone/iPod touch ($99)
•         appstore

•
iPhone VS Android
objective-c
Objective C
•
•
•   runtime
•   foudation framework: values and collection classes
•
•   category
•   protocol
Sample Code
   hello world
Beginning to iPhone development
objective c
•   @

    •   @interface, @implementation, @class

    •   @property, @synthesize

    •   @protocol

    •   NSString* str = @”hello world”

•                       [receiver message]

•           C                 C++
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Sample Code
  class and message
runtime
•   id
•   class & className
•   respondsToSelector
•   performSelector
•   isKindOfClass (super class included)
•   isMemberOfClass
•   @selector
@selector


• SEL
•       C++
Beginning to iPhone development
Beginning to iPhone development
action
CGRect rect = CGRectMake(20, 20, 100, 30);
UIButton* myButton = [UIButton
buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = rect;
[myButton setTitle:@"my button"
forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(btnClick:)
forControlEvents : UIControlEventTouchUpInside];
[self.view addSubview:myButton];
Sample
runtime & selector
Foundation Framework
• Value and Collection Classes
• User defaults
• Archiving
• Task, timers, thread
• File system, I/0
• etc ...
Value and Collection
           Classes
•   NSString & NSMutableString
•   NSArray & NSMutableArray
•   NSDictionary & NSMutableDictionary
•   NSSet & NSMutableSet
•   NSNumber [a obj-c object wrapper for basic C
    type]
    •   (NSNumber* num = [NSNumber
        numberWithInt:3])
Sample Code
  collection classes
•                   alloc   new

•   alloc&dealloc    C++ new&delete

•   but with ...
•           alloc   new         copy
                                   1.
                                          retain

     release
•                                0
    Obj-C                       dealloc
                      dealloc
                                        dealloc
Sample Code
  “           ”      ...
 memory management
Getter & Setter
  @property & @synthesize
•       new   alloc    copy
                                 1.

    release

•
                      retain release
but how to solve this ?
- (Person*) getChild {
    Person* child = [[Person alloc] init];
    [child setName:@”xxxx”];
    ....
    // will return ... [child release] or not ?
    return child;
}
Autorelease
• NSAutoreleasePool* pool ...
• [object autorelease]
•                     autorelease

  NSAutoreleasePool

  release
That’s why create pool
            first ...
int main(int argc, char* argv[]) {
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    // put your own code here ...
    [pool release];
}
how to solve this ?
- (Person*) getChild {
    Person* child = [[Person alloc] init];
    [child setName:@”xxxx”];
    ....
    // will return ... [child release] or not ?
    return [child autorelease];
}
Autorelease Pool
•
    •                    NSMutableArray pool
    •   autorelease             Array
    •             pool            Array
        release

•                             autorelease pool
           autorelease
    pool                          pool
Autorelease Pool Stack
NSAutoreleasePool* poolFirst ..
for (int i=0; i < 10000; i++) {
    NSAutoreleasePool* poolSecond ...
    // have some autorelease object
    // [object autorelease]
    [poolSecond release];
}
// other code
[poolFirst release];
Autorelease Pool
•
    •   NSAutoreleasePool


    •                 alloc            release
    •               Autorelease pool      retain
        autorelease   [pool retain] or [pool autorelease]
    •   AutoreleasePool                                     “
                   ”
    •               pool             pool
                    iphone
          release        autorelease
•   new   alloc    copy
                  1.
                     release autorelease
•
                    1

     [NSString stringWithString:@”objc”]
•
                  retain release
Category
Sample Code
   category
NSString   Class
Cluster ...
Sample Code
something about class cluster ...
Category
•
•
•
Protocol
•   familiar with C++ virtual class
•   familiar with Java’s interface
•

•                          @optional
                     @required
              warning          required
protocol

@protocol TwoMethod
  - (void) oneMethod;
  - (void) anotherMethod;
@end
Class & Protocol
@interface MyClass : NSObject <TwoMethod> {
}
@end


@implementation MyClass
-(void) oneMethod {
    // oneMethod’s implementation
}
- (void) anotherMethod {
    // anotherMethod’s implementation
}
@end
Sample Code
   protocol
Objective C
•
•
•   runtime    id, @selector, respondsToSelector ...
•   foudation framework: values and collection classes
•
•   category                  class cluster “      ”
•   protocol
Using Objective-C Now !

• without mac
• ubuntu:
  • sudo apt-get install gnustep gnustep-devel
  • bash /usr/share/GNUstep/Makefiles/
    GNUstep.sh
  • GNUmakefile
• http://forum.ubuntu.org.cn/viewtopic.php?
  t=190168
iPhone UIKit
iPhone Application
•           &
• MVC
• Views (design & life cycle)
• Navigation based & Tab Bar based application
• very important TableView
•
• Web service
Beginning to iPhone development
UIApplication
•   Every application must have exactly one instance of
    UIApplication (or a subclass of UIApplication). When
    an application is launched, the UIApplicationMain
    function is called; among its other tasks, this
    function create a singleton UIApplication object.

•   The application object is typically assigned a
    delegate, an object that the application informs of
    significant runtime events—for example, application
    launch, low-memory warnings, and application
    termination—giving it an opportunity to respond
    appropriately.
Beginning to iPhone development
Beginning to iPhone development
UIApplicationMain

• delegateClassName
 • Specify nil if you load the delegate object
    from your application’s main nib file.
• from Info.plist get main nib file
• from main nib file get the application’s
  delegate
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
UIControl

• UILabel
• UIButton
• UITableView
• UINavigatorBar
• ...
- design time
Demo
button click
Without IB ?
create a button and bind event by code
Beginning to iPhone development
Beginning to iPhone development
Views
•   View                            view
    superview                   subviews
•       iphone app             window    Views
    window     window                   view (top level)

•   view
    •   - (void)addSubview:(UIView *)view;
    •   - (void)removeFromSuperview;
•   Superviews retain their subviews
•   UIView            CGRect                 CGPoint
      CGSize
View’s life cycle & hook
        function
•   initWithNibName:bundle
•   viewDidLoad
•   viewWillAppear
•   viewWillDisappear
•   ...maybe viewDidUnload
•   hook function
    •   shouldAutorotateToInterfaceOrientation
    •   didReceiveMemoryWarning
Navigation Controller
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
UINavigationController

•   manages the currently displayed screens using the
    navigation stack
•   at the bottom of this stack is the root view controller
•   at the top of the stack is the view controller currently
    being displayed
•   method:
    •   pushViewController:animated:
    •   popViewControllerAnimated:
Demo
UINavigationController
TabBar Controller
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
UITabBarController
• implements a specialized view controller that
  manages a radio-style selection interface
• When the user selects a specific tab, the tab
  bar controller displays the root view of the
  corresponding view controller, replacing any
  previous views
• init with an array (has many view controllers)
Demo
UITabBarController
Combine


•              UI

    • TabBarController Based +
      NavigationController
Beginning to iPhone development
Beginning to iPhone development
Demo
Combine UITabBarController &
   UINavigationController
TableView

• display a list of data
 • Single column, multiple rows
 • Vertical scrolling
• Powerful and ubiquitous in iPhone
  applications
Beginning to iPhone development
Beginning to iPhone development
Display data in Table View
•
    •    Table views display a list of data, so use an array
    •    [myTableView setList:myListOfStuff];
    •
        •   All data is loaded upfront
        •   All data stays in memory
•
    •    Another object provides data to the table view
        •   Not all at once
        •   Just as it’s needed for display
    •    Like a delegate, but purely data-oriented
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Beginning to iPhone development
Demo
UITableView <UITableViewDataSource>
Beginning to iPhone development
Beginning to iPhone development
Selection
Beginning to iPhone development
Demo
UITableView <UITableViewDelegate>
UITabBar + UINavigation + UITableView !

NavigationController

                                 TableViewController




                                 TabBarController
Demo
UITabBar + UINavigation + UITableView
• Propery Lists, NSUserDefaults
• SQLite
• Core Data
SandBox

• Why keep applications separate?
 • Security
 • Privacy
 • Cleanup after deleting an app
Sample: /Users/xxx/library/Application Support/iPhone Simulator/4.0/Applications
Beginning to iPhone development
Beginning to iPhone development
Property Lists
•       Convenient way to store a small amount of data
    •    Arrays, dictionaries, strings, numbers, dates, raw data
    •    Human-readable XML or binary format
•   NSUserDefaults class uses property lists under the hood
•   When Not to Use Property Lists

    •    More than a few hundred KB of data

    •    Custom object types

    •    Multiple writers (e.g. not ACID)
Beginning to iPhone development
Beginning to iPhone development
Demo
Save data with NSUserDefaults
SQLite
•   Complete SQL database in an ordinary file
•   Simple, compact, fast, reliable
•   No server
•   Great for embedded devices
    •   Included on the iPhone platform
•   When Not to Use SQLite
    •   Multi-gigabyte databases
    •   High concurrency (multiple writers)
    •   Client-server applications
Beginning to iPhone development
SQLite Obj-C Wrapper

•   http://code.google.com/p/flycode/source/browse/
    trunk/fmdb

•   A query maybe like this:

    •   [dbconn executeQuery:@"select * from call"]
Beginning to iPhone development
Using Web Service
•   Two Common ways:
•   XML
    •   libxml2
        •   Tree-based: easy to parse, entire tree in memory
        •   Event-driven: less memory, more complex to manage state
    •   NSXMLParser
        •   Event-driven API: simpler but less powerful than libxml2
•   JSON
    •   Open source json-framework wrapper for Objective-C
    •   http://code.google.com/p/json-framework/
NSURLConnection
•   NSMutableURLRequest
•   - connectionWithRequest: delegate
•   delegate method:
    •   – connection:didReceiveResponse:
    •   – connection:didReceiveData:
    •   – connection:didFailWithError:
    •   – connectionDidFinishLoading:
Demo
use json-framework and NSURLConnection with hi-api
iPhone Application

•              &
•   MVC
•   Views (design & life cycle)
•   Navigation based & Tab Bar based application
    & TableView
•                        (sandbox, property list,
    sqlite)
•   Web service
•       Objective-C
•       The iPhone Developer’s Cookbook
•       Programming in Objective-C 2.0
•
•           Stanford iPhone dev course
    •       iTunes iTune Store    cs193p
                       mac windows
Q &A
The End

More Related Content

PDF
Automatic Reference Counting @ Pragma Night
PDF
Automatic Reference Counting
PDF
FI MUNI 2012 - iOS Basics
PDF
iOS 2 - The practical Stuff
PPTX
Awesomeness of JavaScript…almost
ZIP
iOS Memory Management Basics
PDF
Arquitetando seu app Android com Jetpack
PDF
Persisting Data on SQLite using Room
Automatic Reference Counting @ Pragma Night
Automatic Reference Counting
FI MUNI 2012 - iOS Basics
iOS 2 - The practical Stuff
Awesomeness of JavaScript…almost
iOS Memory Management Basics
Arquitetando seu app Android com Jetpack
Persisting Data on SQLite using Room

What's hot (19)

PDF
Django at Scale
PDF
iPhone Memory Management
PDF
User defined-functions-cassandra-summit-eu-2014
PDF
iOS 7 SDK特訓班
PDF
Memory Management on iOS
PDF
ARCでめちゃモテiOSプログラマー
PPT
Memory management in Objective C
PPT
Objective C Memory Management
PPTX
JavaScript!
PDF
XQuery Design Patterns
PPTX
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
PPT
jQuery Objects
PPTX
Getting started with jQuery
PDF
Cassandra and materialized views
PDF
Multithreading on iOS
PPTX
iOS Memory Management
PPT
Ios - Introduction to memory management
PPTX
Mastering Java Bytecode With ASM - 33rd degree, 2012
PDF
iOS App with Parse.com as RESTful Backend
Django at Scale
iPhone Memory Management
User defined-functions-cassandra-summit-eu-2014
iOS 7 SDK特訓班
Memory Management on iOS
ARCでめちゃモテiOSプログラマー
Memory management in Objective C
Objective C Memory Management
JavaScript!
XQuery Design Patterns
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
jQuery Objects
Getting started with jQuery
Cassandra and materialized views
Multithreading on iOS
iOS Memory Management
Ios - Introduction to memory management
Mastering Java Bytecode With ASM - 33rd degree, 2012
iOS App with Parse.com as RESTful Backend
Ad

Viewers also liked (15)

PDF
self and super in objc
KEY
よくわかるオンドゥル語
PPTX
Defnydd trydan Ysgol y Frenni
PPTX
Method Shelters : Another Way to Resolve Class Extension Conflicts
PDF
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
KEY
Romafs
PDF
Tales@tdc
KEY
RubyistのためのObjective-C入門
PDF
Qcon beijing 2010
KEY
Objective-C Survives
PDF
Présentation gnireenigne
PDF
Http Live Streaming Intro
PPTX
Http live streaming technical presentation
PDF
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
PDF
HTTP Live Streaming
self and super in objc
よくわかるオンドゥル語
Defnydd trydan Ysgol y Frenni
Method Shelters : Another Way to Resolve Class Extension Conflicts
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
Romafs
Tales@tdc
RubyistのためのObjective-C入門
Qcon beijing 2010
Objective-C Survives
Présentation gnireenigne
Http Live Streaming Intro
Http live streaming technical presentation
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
HTTP Live Streaming
Ad

Similar to Beginning to iPhone development (20)

PDF
MFF UK - Introduction to iOS
PPTX
iOS Session-2
PPTX
iOS Development (Part 2)
PPTX
Ios development
PPT
Ios development
PDF
Objective-C Is Not Java
KEY
Objective-C Crash Course for Web Developers
KEY
Objective-C & iPhone for .NET Developers
PDF
Write native iPhone applications using Eclipse CDT
PDF
Louis Loizides iOS Programming Introduction
PDF
02 objective-c session 2
PDF
iOS Programming Intro
PDF
Iphone course 2
PDF
iOS 101 - Xcode, Objective-C, iOS APIs
PDF
iPhone SDK dev sharing - the very basics
PDF
Bootstrapping iPhone Development
PDF
iPhone Seminar Part 2
PPTX
iOS,From Development to Distribution
PPTX
Hello world ios v1
KEY
漫游iOS开发指南
MFF UK - Introduction to iOS
iOS Session-2
iOS Development (Part 2)
Ios development
Ios development
Objective-C Is Not Java
Objective-C Crash Course for Web Developers
Objective-C & iPhone for .NET Developers
Write native iPhone applications using Eclipse CDT
Louis Loizides iOS Programming Introduction
02 objective-c session 2
iOS Programming Intro
Iphone course 2
iOS 101 - Xcode, Objective-C, iOS APIs
iPhone SDK dev sharing - the very basics
Bootstrapping iPhone Development
iPhone Seminar Part 2
iOS,From Development to Distribution
Hello world ios v1
漫游iOS开发指南

Recently uploaded (20)

PPTX
A Presentation on Artificial Intelligence
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
MYSQL Presentation for SQL database connectivity
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Machine learning based COVID-19 study performance prediction
PDF
Modernizing your data center with Dell and AMD
PPT
Teaching material agriculture food technology
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
A Presentation on Artificial Intelligence
Diabetes mellitus diagnosis method based random forest with bat algorithm
Reach Out and Touch Someone: Haptics and Empathic Computing
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
MYSQL Presentation for SQL database connectivity
The AUB Centre for AI in Media Proposal.docx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
Understanding_Digital_Forensics_Presentation.pptx
Big Data Technologies - Introduction.pptx
Unlocking AI with Model Context Protocol (MCP)
Machine learning based COVID-19 study performance prediction
Modernizing your data center with Dell and AMD
Teaching material agriculture food technology
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Chapter 3 Spatial Domain Image Processing.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Per capita expenditure prediction using model stacking based on satellite ima...

Beginning to iPhone development

  • 1. iPhone Objective-C, UIKit bofeng@corp.netease.com @vonbo
  • 4. First iPhone App • Hello world!
  • 5. Things we have • Hello world!
  • 6. • xcode SDK • & test with Simulator • test with iPhone/iPod touch ($99) • appstore •
  • 9. Objective C • • • runtime • foudation framework: values and collection classes • • category • protocol
  • 10. Sample Code hello world
  • 12. objective c • @ • @interface, @implementation, @class • @property, @synthesize • @protocol • NSString* str = @”hello world” • [receiver message] • C C++
  • 17. Sample Code class and message
  • 18. runtime • id • class & className • respondsToSelector • performSelector • isKindOfClass (super class included) • isMemberOfClass • @selector
  • 22. action CGRect rect = CGRectMake(20, 20, 100, 30); UIButton* myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = rect; [myButton setTitle:@"my button" forState:UIControlStateNormal]; [myButton addTarget:self action:@selector(btnClick:) forControlEvents : UIControlEventTouchUpInside]; [self.view addSubview:myButton];
  • 24. Foundation Framework • Value and Collection Classes • User defaults • Archiving • Task, timers, thread • File system, I/0 • etc ...
  • 25. Value and Collection Classes • NSString & NSMutableString • NSArray & NSMutableArray • NSDictionary & NSMutableDictionary • NSSet & NSMutableSet • NSNumber [a obj-c object wrapper for basic C type] • (NSNumber* num = [NSNumber numberWithInt:3])
  • 26. Sample Code collection classes
  • 27. alloc new • alloc&dealloc C++ new&delete • but with ...
  • 28. alloc new copy 1. retain release • 0 Obj-C dealloc dealloc dealloc
  • 29. Sample Code “ ” ... memory management
  • 30. Getter & Setter @property & @synthesize
  • 31. new alloc copy 1. release • retain release
  • 32. but how to solve this ? - (Person*) getChild { Person* child = [[Person alloc] init]; [child setName:@”xxxx”]; .... // will return ... [child release] or not ? return child; }
  • 33. Autorelease • NSAutoreleasePool* pool ... • [object autorelease] • autorelease NSAutoreleasePool release
  • 34. That’s why create pool first ... int main(int argc, char* argv[]) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; // put your own code here ... [pool release]; }
  • 35. how to solve this ? - (Person*) getChild { Person* child = [[Person alloc] init]; [child setName:@”xxxx”]; .... // will return ... [child release] or not ? return [child autorelease]; }
  • 36. Autorelease Pool • • NSMutableArray pool • autorelease Array • pool Array release • autorelease pool autorelease pool pool
  • 37. Autorelease Pool Stack NSAutoreleasePool* poolFirst .. for (int i=0; i < 10000; i++) { NSAutoreleasePool* poolSecond ... // have some autorelease object // [object autorelease] [poolSecond release]; } // other code [poolFirst release];
  • 38. Autorelease Pool • • NSAutoreleasePool • alloc release • Autorelease pool retain autorelease [pool retain] or [pool autorelease] • AutoreleasePool “ ” • pool pool iphone release autorelease
  • 39. new alloc copy 1. release autorelease • 1 [NSString stringWithString:@”objc”] • retain release
  • 41. Sample Code category
  • 42. NSString Class Cluster ...
  • 43. Sample Code something about class cluster ...
  • 45. Protocol • familiar with C++ virtual class • familiar with Java’s interface • • @optional @required warning required
  • 46. protocol @protocol TwoMethod - (void) oneMethod; - (void) anotherMethod; @end
  • 47. Class & Protocol @interface MyClass : NSObject <TwoMethod> { } @end @implementation MyClass -(void) oneMethod { // oneMethod’s implementation } - (void) anotherMethod { // anotherMethod’s implementation } @end
  • 48. Sample Code protocol
  • 49. Objective C • • • runtime id, @selector, respondsToSelector ... • foudation framework: values and collection classes • • category class cluster “ ” • protocol
  • 50. Using Objective-C Now ! • without mac • ubuntu: • sudo apt-get install gnustep gnustep-devel • bash /usr/share/GNUstep/Makefiles/ GNUstep.sh • GNUmakefile • http://forum.ubuntu.org.cn/viewtopic.php? t=190168
  • 52. iPhone Application • & • MVC • Views (design & life cycle) • Navigation based & Tab Bar based application • very important TableView • • Web service
  • 54. UIApplication • Every application must have exactly one instance of UIApplication (or a subclass of UIApplication). When an application is launched, the UIApplicationMain function is called; among its other tasks, this function create a singleton UIApplication object. • The application object is typically assigned a delegate, an object that the application informs of significant runtime events—for example, application launch, low-memory warnings, and application termination—giving it an opportunity to respond appropriately.
  • 57. UIApplicationMain • delegateClassName • Specify nil if you load the delegate object from your application’s main nib file. • from Info.plist get main nib file • from main nib file get the application’s delegate
  • 61. UIControl • UILabel • UIButton • UITableView • UINavigatorBar • ...
  • 64. Without IB ? create a button and bind event by code
  • 67. Views • View view superview subviews • iphone app window Views window window view (top level) • view • - (void)addSubview:(UIView *)view; • - (void)removeFromSuperview; • Superviews retain their subviews • UIView CGRect CGPoint CGSize
  • 68. View’s life cycle & hook function • initWithNibName:bundle • viewDidLoad • viewWillAppear • viewWillDisappear • ...maybe viewDidUnload • hook function • shouldAutorotateToInterfaceOrientation • didReceiveMemoryWarning
  • 77. UINavigationController • manages the currently displayed screens using the navigation stack • at the bottom of this stack is the root view controller • at the top of the stack is the view controller currently being displayed • method: • pushViewController:animated: • popViewControllerAnimated:
  • 85. UITabBarController • implements a specialized view controller that manages a radio-style selection interface • When the user selects a specific tab, the tab bar controller displays the root view of the corresponding view controller, replacing any previous views • init with an array (has many view controllers)
  • 87. Combine • UI • TabBarController Based + NavigationController
  • 90. Demo Combine UITabBarController & UINavigationController
  • 91. TableView • display a list of data • Single column, multiple rows • Vertical scrolling • Powerful and ubiquitous in iPhone applications
  • 94. Display data in Table View • • Table views display a list of data, so use an array • [myTableView setList:myListOfStuff]; • • All data is loaded upfront • All data stays in memory • • Another object provides data to the table view • Not all at once • Just as it’s needed for display • Like a delegate, but purely data-oriented
  • 109. UITabBar + UINavigation + UITableView ! NavigationController TableViewController TabBarController
  • 111. • Propery Lists, NSUserDefaults • SQLite • Core Data
  • 112. SandBox • Why keep applications separate? • Security • Privacy • Cleanup after deleting an app
  • 116. Property Lists • Convenient way to store a small amount of data • Arrays, dictionaries, strings, numbers, dates, raw data • Human-readable XML or binary format • NSUserDefaults class uses property lists under the hood • When Not to Use Property Lists • More than a few hundred KB of data • Custom object types • Multiple writers (e.g. not ACID)
  • 119. Demo Save data with NSUserDefaults
  • 120. SQLite • Complete SQL database in an ordinary file • Simple, compact, fast, reliable • No server • Great for embedded devices • Included on the iPhone platform • When Not to Use SQLite • Multi-gigabyte databases • High concurrency (multiple writers) • Client-server applications
  • 122. SQLite Obj-C Wrapper • http://code.google.com/p/flycode/source/browse/ trunk/fmdb • A query maybe like this: • [dbconn executeQuery:@"select * from call"]
  • 124. Using Web Service • Two Common ways: • XML • libxml2 • Tree-based: easy to parse, entire tree in memory • Event-driven: less memory, more complex to manage state • NSXMLParser • Event-driven API: simpler but less powerful than libxml2 • JSON • Open source json-framework wrapper for Objective-C • http://code.google.com/p/json-framework/
  • 125. NSURLConnection • NSMutableURLRequest • - connectionWithRequest: delegate • delegate method: • – connection:didReceiveResponse: • – connection:didReceiveData: • – connection:didFailWithError: • – connectionDidFinishLoading:
  • 126. Demo use json-framework and NSURLConnection with hi-api
  • 127. iPhone Application • & • MVC • Views (design & life cycle) • Navigation based & Tab Bar based application & TableView • (sandbox, property list, sqlite) • Web service
  • 128. Objective-C • The iPhone Developer’s Cookbook • Programming in Objective-C 2.0 • • Stanford iPhone dev course • iTunes iTune Store cs193p mac windows