1 / 19

iPhone 101

Learn the basics of iPhone app development using Objective-C, including working with UI elements, debugging with Xcode, and utilizing the iOS simulator. Explore topics such as inheritance, categories, properties, and delegates. Discover the Cocoa Touch API and its data types, collections, and built-in features. Dive into the anatomy of an iPhone app, including app delegates, navigation and tab bars, view controllers, and event handling. Get hands-on experience with a tab-bar based app and learn about memory management and localization.

libba
Download Presentation

iPhone 101

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. iPhone 101

  2. Outline • Objective-C • Random bits of the API • Using the simulator • Debugging with Xcode

  3. Objective-C • Superset of 'C' with OO stuff added • C++ classes → interface/implementation • C++ methods → messages • No static member variables • Only need to declare public methods or those needed before the implementation • Inheritance with Java-like multiple inheritance (using protocols)

  4. Objective-C • File extensions: .h, .m, and .mm • Class definition:

  5. Objective-C

  6. More Objective-C • Object allocation, destruction and reference counting using retain/release/autorelease • Categories • Properties • Delegate objects using @protocols

  7. More Objective-C • Most Objective-C methods return the object itself (as an 'id') so you can chain calls in a single statement.

  8. More Objective-C (categories)

  9. More Objective-C (properties)

  10. More Objective-C (delegates)

  11. Cocoa Touch API • Data types: id, BOOL, NSInteger, NSUInteger, NSNumber, NSString, long long • Collections: NSDictionary, NSArray, NSSet and their mutable friends • NSTimer, NSThread*, NSURLConnection • UIResponder for managing the responder chain and touch events • Core Graphics, Core Animation, Core Audio, Core Location *Note: @synchronized (obj) can be used by multi-threaded apps

  12. Anatomy of an iPhone app • App delegate: lifecycle (ex: applicationDidFinishLaunching, applicationWillTerminate) • Navigation bar, tab bar, and view controllers • Event driven using a “run loop” (provided for main thread) • Register “selectors” to handle events: syntax: @selector(methodName:arg1:arg2:) • Implement delegate protocols to handle events from various UI/data objects

  13. Anatomy of an iPhone app • UI construction – code or Interface builder • UIKit is the iPhone UI framework • UIViewController for managing screens • UI elements: UIView, UIImageView, UIButton, UIPickerView, UILabel, UITextView, UITableView, UIAlertView, etc. • Some UIView useful methods: • addSubview and removeFromSuperview • beginAnimations:context: method and transform property for simple implicit animation

  14. Anatomy of an iPhone app • UINavigationBar / Item • UIBarButtonItem • UIImageView / UIImage • UILabel • UITextField • UIButton • UITabBarController • UITabBarItem/badgeValue

  15. Tab bar components

  16. Navigation item components

  17. UICatalog sample app

  18. iPhone SDK miscellany • retain/release/autorelease carefully! • SDK class factory functions usually return autorelease'd objects (ex: [NSString stringWithFormat...]) • A view-controller's loadView can get called multiple times if the view is released due to low memory • Localizing strings using NSLocalizedString • User-defined “OTHER_CFLAGS” for build flags

  19. Workshop - A simple tab-bar based iPhone app • Enable code in applicationDidFinishLaunching to add one view controller • In FirstViewController, add a red box at 10,10 which is 100x100 using UIView::initWithFrame and CGRectMake() • Add a white label in that box at 10,10 with a 12pt system font • Add a second view controller and give it a yellow background • Add names and tab bar images (UITabBarSystemItem) to both view controllers • Inspect code for memory leaks. Did you remember to release after adding views to subviews? • In the second view controller, use a timer (NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:) with 1 second interval to increment a counter (an instance of UILabel) somewhere in the middle of the screen. Use NSString::stringWithFormat to convert a number to a string printf-style. • Use Xcode to set breakpoints and inspect variables

More Related