iOS SDK Programming: A Beginner’s Guide docx

529 1K 0
iOS SDK Programming: A Beginner’s Guide docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info iOS SDK Programming: A Beginner’s Guide www.it-ebooks.info About the Authors James A. Brannan is a senior developer with more than 15 years of experience. He has developed using everything from AWK, to Visual Basic, to Java. His current interests are iOS, Blackberry, Android, and Adobe Flex/Flash. He is only $999,000 short of being the next app store overnight millionaire. He lives in Gaithersburg, Maryland, with his wife, two kids, two Macs, and bicycle. Blake Ward has a PhD in Computer Science from Carnegie Mellon University and has spent more than 30 years programming and managing software development. He has developed for a wide variety of mobile devices, ranging from the Apple Newton and Palm Pilot to RIM’s Blackberry, the iPhone and iPad, and Android phones. Blake has worked as a researcher and in management at Apple, Xerox PARC, and numerous startups. He is currently an independent iPhone and Android developer, available through www.iphoneappquotes.com. About the Technical Editor Born to golf, forced to work, Steven Weber, a Java Web Applications engineer, has ten years application development under his belt. He’s dabbled in iOS application development and released one corporate application since the launch of Apple’s App Store. He’s currently living it up in the Colorado Rockies. www.it-ebooks.info iOS SDK Programming: A Beginner’s Guide James A. Brannan Blake Ward New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto www.it-ebooks.info Copyright © 2011 by The McGraw-Hill Companies. All rights reserved. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher. ISBN: 978-0-07-175909-0 MHID: 0-07-175909-3 The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-175908-3, MHID: 0-07-175908-5. All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefi t of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps. McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs. To contact a representative please e-mail us at bulksales@mcgraw-hill.com. Information has been obtained by McGraw-Hill from sources believed to be reliable. However, because of the possibility of human or mechanical error by our sources, McGraw-Hill, or others, McGraw-Hill does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use of such information. TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGrawHill”) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms. THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise. www.it-ebooks.info For Timothy Hill and Doctor Ronald Holt. This book is not some lofty political or anthropological treatise, but it was fun writing. —James For Bryce—the real author in our family. —Blake www.it-ebooks.info This page intentionally left blank www.it-ebooks.info vii Contents at a Glance 1 The iOS Software Development Kit (SDK) 1 2 A C Refresher 25 3 Just Enough Objective-C: Part One 41 4 Just Enough Objective-C: Part Two 61 5 Deploying to an iPhone, Debugging, and Testing 77 6 UIApplication and UIApplicationDelegate 109 7 UIView and UIViewController 127 8 UITabBar and UITabBarController 141 9 UINavigationBar and UINavigationController 159 10 Tables Using UITableView and UITableViewController 185 11 Activity Progress and Alerting Users 237 12 Controls—Part One: Using Buttons, Sliders, Switches, and Text Fields 263 www.it-ebooks.info viii iOS SDK Programming: A Beginner’s Guide 13 Controls—Part Two: Using Pickers and Using the Camera 295 14 Application Settings 329 15 Property Lists and Archiving 349 16 Data Persistence Using SQLite 371 17 Core Data 399 18 Multimedia 435 19 Universal Applications for the iPad 457 Index 485 www.it-ebooks.info ix Contents ACKNOWLEDGMENTS xvii INTRODUCTION xix 1 The iOS Software Development Kit (SDK) 1 The App Store 2 The Software Development Kit (SDK) 4 Paid Membership 5 Objective-C, Foundation Framework, Cocoa Touch, and UIKit 5 Cocoa Touch 6 Foundation Framework 6 The iOS Frameworks 6 Memory and Processor Speed 8 Small Screen 8 Security 9 Short-Lived Applications 9 Manual Memory Management 9 Relevant Documentation 9 Try This: Getting a Quick Start on iOS Development 10 Summary 23 2 A C Refresher 25 C Command-Line Programs 27 Try This: Creating a Simple C Program Using Xcode 27 www.it-ebooks.info [...]... Chapter 1: The iOS Software Development Kit (SDK) Framework Purpose Accelerate Accelerating math functions AddressBook Accessing user’s contacts AddressBookUI Displaying Addressbook AssetsLibrary Accessing user’s photos and videos AudioToolbox Audio data streams; playing and recording audio AudioUnit Audio units AVFoundation Objective-C interfaces for audio playback and recording CFNetwork WiFi and... garbage collection, and you must manage memory yourself Although manual memory management can be a pain, it is not a huge limitation Just be aware that forgetting to release an object is all too easy a mistake to make As you will see in Chapter 5, there are tools to help you track down and fix these errors Relevant Documentation Apple provides considerable online documentation You have access to that... 138 140 8 UITabBar and UITabBarController UITabBar, UITabBarController, UITabBarItem, and UITabBarControllerDelegate Try This: Using the Tab Bar Application Template Try This: Adding a Tab Bar Item to a Tab Bar Application Try This: Creating a Tab Bar Application from Scratch Try This: Allowing Users... Finally, Chapter 19 discusses the new SDK functionality available for the iPad and shows you how to create a universal application that will run on the iPhone or iPod touch but also take full advantage of the larger display on the iPad when available All of the framework functionality described in the earlier chapters applies to the iPad and the new iPhone 4, so this chapter focuses on how to layer... layout and rendering CoreVideo Pipeline model for digital video EventKit Accessing user’s calendar EventKitUI Displaying standard system calendar ExternalAccessory Hardware accessory communication interfaces Foundation Cocoa foundation layer GameKit Peer-to-peer connectivity iAd Displaying advertisements ImageIO Reading and writing image data IOKit Low-level library for developing iPhone hardware attachments... iPhone and iPad device’s technology layers Cocoa Touch Objective-C Cocoa Layer Media iPhone OS C Layer Core Services Figure 1-4 The iPhone and iPad device’s programming layers www.it-ebooks.info 5 6 iOS SDK Programming: A Beginner’s Guide The Media layer is also rather low-level and contains C application programming interfaces (APIs) like OpenGL ES, Quartz, and Core Audio The Cocoa layer overlays the... developing iPhone hardware attachments MapKit Embedding map in application and geocoding coordinates MediaPlayer Video playback MessageUI Composing e-mail messages OpenAL Positional audio library Table 1-1 Frameworks in iOS www.it-ebooks.info 7 8 iOS SDK Programming: A Beginner’s Guide Framework Purpose OpenGLES Embedded OpenGL (2-D and 3-D graphics rendering) QuartzCore Core animation QuickLook Previewing... www.it-ebooks.info Acknowledgments T hanks to the technical editor, Steven Weber, and everybody at McGraw-Hill, particularly Roger Stewart, Joya Anthony, Jody McKenzie, Vastavikta Sharma, and Bob Campbell Special thanks to Everaldo and his Crystal Project Icons licensed under the LGPL These icons have made the examples much more visually appealing in both this book and others And of course, thanks to Neil Salkind,... classes TIP See Apple’s Foundation Framework Reference for a complete listing of the classes and protocols provided by the Foundation framework NOTE If you are a Java programmer, think of the iOS s programming environment like this: Objective-C is equivalent to Java’s core syntax The Foundation framework is equivalent to Java’s core classes, such as ArrayList, Exception, HashMap, String, Thread, and... think in terms of having a single window and swapping views based on interaction from your user Security You can only read or write to directories that are part of your application’s bundle or your application’s documents directory Areas accessible to your application are said to be in your application’s sandbox You cannot read files created by other applications unless the application places the files . 436 AudioServicesPlaySystemSound 437 AVAudioPlayer and AVAudioPlayerDelegate 438 Try This: Playing a Sound and an MP3 439 Media Player Framework 442 Media Data Classes. 140 8 UITabBar and UITabBarController 141 UITabBar, UITabBarController, UITabBarItem, and UITabBarControllerDelegate 142 Try This: Using the Tab Bar Application

Ngày đăng: 24/03/2014, 01:21

Từ khóa liên quan

Mục lục

  • Contents

  • Acknowledgments

  • Introduction

  • 1 The iOS Software Development Kit (SDK)

    • The App Store

    • The Software Development Kit (SDK)

      • Paid Membership

    • Objective-C, Foundation Framework, Cocoa Touch, and UIKit

      • Cocoa Touch

      • Foundation Framework

      • The iOS Frameworks

      • Memory and Processor Speed

      • Small Screen

      • Security

      • Short-Lived Applications

      • Manual Memory Management

    • Relevant Documentation

    • Try This: Getting a Quick Start on iOS Development

    • Summary

  • 2 A C Refresher

    • C Command-Line Programs

    • Try This: Creating a Simple C Program Using Xcode

    • C Comments

    • Understanding Headers, Import, and Include

    • Try This: Creating a Header File

    • Preprocessor Statements

    • Try This: Using Preprocessor Statements

    • Data Types and Operators

    • Control, Functions, and Conditional Statements

    • Arrays and Structures

    • Functions

    • The printf Statement

    • Pointers

    • Try This: Using Pointers

    • Dereferencing a Pointer

    • Pointers and Arrays

    • Try This: Using an Array with Pointers

    • Summary

  • 3 Just Enough Objective-C: Part One

    • Objective-C Classes and Objects

    • Class Interface and Implementation

    • Try This: Generating an Objective-C Class’ Interface and Implementation

    • The @interface and @implementation Compiler Directives

    • Method Declaration and Definition

    • Try This: Adding SayHello to the Simple Class

    • Interface Anatomy

    • Implementation Anatomy

    • Public, Private, and Protected Instance Variables

    • Understanding Simple Messaging

    • Using self in a Message

    • Nested Arguments

    • Class and Instance Methods

    • Try This: Adding sayGoodBye as a Class Method

    • The alloc and init Methods

    • Managing Memory Using Retain and Release

    • Try This: Using Manual Memory Management

    • Instance Variables and Memory

    • Managing Memory Using Autorelease

    • Summary

  • 4 Just Enough Objective-C: Part Two

    • Properties

      • Retain

      • Assign

      • Copy

      • Releasing Properties

    • Multiple-Argument Messages

    • Try This: Creating a Simple Multiple-Argument Message

    • Understanding the id Variable Type, Dynamic Typing, and Dynamic Binding

      • The id Type

      • Dynamic Binding and Dynamic Typing

    • Understanding Inheritance

      • Overriding Methods

      • Overloading Methods

    • Using Categories

    • Using Protocols

    • Handling Exceptions

    • Summary

  • 5 Deploying to an iPhone, Debugging, and Testing

    • Installing Applications on an iPhone

      • Membership

      • Certificates, Devices, Application IDs, and Provisioning

    • Try This: Deploying an Application to iPhone

    • Debugging

      • Using the Debugger

    • Try This: Debugging an Application

      • NSZombieEnabled

    • Try This: Enabling Zombies

      • Instruments—Leaks

    • Try This: Find a Memory Leak

    • Distributing Your Application

      • Ad Hoc Deployment and Testing

      • Distributing Your App via the App Store

    • Summary

  • 6 UIApplication and UIApplicationDelegate

    • Try This: Adding a UIView and UIViewController to a UIApplicationDelegate

    • Connecting UIWindow, UIApplication, and UIApplicationDelegate

    • Try This: Exploring Main Window.xib

    • UIApplication and UIApplicationDelegate

      • The main.m File

      • Handling Application Life Cycle Events

      • Application Interruptions

    • Try This: Handling Application Interruptions

    • Summary

  • 7 UIView and UIViewController

    • The UIView Class

    • The UIViewController Class

    • View-Based Application Template

    • IBOutlet and IBAction

    • Try This: Using a View-Based Application Template

    • Try This: Using a Window-Based Application Template

    • UIViewController and Application Life Cycle Events

    • Try This: Exploring Several Life Cycle Methods

    • Summary

  • 8 UITabBar and UITabBarController

    • UITabBar, UITabBarController, UITabBarItem, and UITabBarControllerDelegate

    • Try This: Using the Tab Bar Application Template

    • Try This: Adding a Tab Bar Item to a Tab Bar Application

    • Try This: Creating a Tab Bar Application from Scratch

    • Try This: Allowing Users to Customize a Tab Bar

    • Summary

  • 9 UINavigationBar and UINavigationController

    • UINavigationBar, UINavigationController, and UINavigationItem

    • Try This: Building a Three-View Application Using a Navigation Bar

      • Adding Another View

    • Try This: See How a Utility Application Uses NavigationBar

    • More on the UINavigationController

      • Popping View Controllers

      • Configuring the Navigation Bar

    • Try This: Using a Navigation Controller in a Tab

    • Summary

  • 10 Tables Using UITableView and UITableViewController

    • UITableView

    • UITableViewDelegate and UITableViewDataSource

      • UITableViewDelegate

      • UITableViewDataSource

    • Try This: Adopting the UITableViewDelegate and UITableViewDataSource

    • Try This: Adding a Delegate and Data Source

    • UITableViewController

    • Try This: Using a UITableViewController

    • Grouping and Indexing

      • Grouped Table Style

    • Try This: Grouping

      • Indexing

    • Try This: Indexing

    • Images in Tables

    • Try This: Adding an Image

    • Selecting Rows

    • Try This: Row Selection

    • Changing Row Height

    • Try This: Changing Row Height

    • Accessorizing Table Cells

    • Try This: Accessorizing a Table Cell

    • Customizing a Table Cell

    • Try This: Customizing a Cell Using Interface Builder

    • Using Tables with Navigation Bars and Tabs

    • Try This: Using a Table in a Navigation Controller in a Tab

    • Editing Table Cells

      • Getting to Edit Mode

      • Edit Mode Methods

    • Try This: Editing Rows

    • Summary

  • 11 Activity Progress and Alerting Users

    • Showing Activity—the UIActivityIndicatorView

    • Try This: Using a UIActivitylndicatorView

    • Showing Progress—the UIProgressView

    • Try This: Using a UIProgress View

    • Alerting Users

    • UIAlertView and UIAlertViewDelegate

    • Try This: Creating a Simple UIAlertView

    • Try This: Using an Alert with Multiple Buttons

    • UIActionSheet and UIActionSheetDelegate

    • Try This: Using a UIActionSheet

    • Application Badges

    • Try This: Adding an Application Badge

    • Summary

  • 12 Controls—Part One: Using Buttons, Sliders, Switches, and Text Fields

    • Buttons

      • UIButton with a Background Image and Image

    • Try This: Using a Custom Button Background Image and Image

    • Button Types

    • UIToolBar

    • Try This: Creating a UIToolbar

    • UISwitch

    • UISlider

      • Appearance

      • Values

      • Continuous Property

    • Try This: Using a Switch and a Slider

    • UITextField

    • Try This: Using UITextField (with a Number Pad)

    • UITextView

    • UISegmentedControl

    • Try This: Using a UISegmentedControl

    • The Web View

      • UIWebView

      • UIWebViewDelegate

    • Try This: Creating a Simple Web Browser

    • Summary

  • 13 Controls—Part Two: Using Pickers and Using the Camera

    • Using Pickers: Date Pickers and Pickers

      • Date Pickers

    • Try This: Using a Date Picker

    • Try This: Using a UIDatePicker in Timer Mode

      • UIPickerView

    • Try This: Using a Picker

    • Try This: Using a UIPickerView with Two Components

    • Try This: Loading UIImageViews into a UIPickerView

    • Using the Camera: UIImagePickerController

      • UIImagePickerController

      • UIImagePickerControllerDelegate

    • Try This: Using the UIImagePickerController

    • Try This: Using Notifications

    • Summary

  • 14 Application Settings

    • The Settings Application

    • The Settings Bundle

    • Try This: Creating a Settings Bundle

      • Settings Field Types

    • Try This: Adding a PSTextFieldSpecifier

      • PSMultiValueSpecifier

    • Try This: Adding a PSMultiValueSpecifier

      • PSToggleSwitchSpecifier

    • Try This: Adding a PSToggleSwitchSpecifier

      • PSSliderSpecifier

    • Try This: Adding a PSSliderSpecifier

      • PSChildPaneSpecifier

    • Try This: Adding a PSChildPaneSpecifier

    • Reading Settings Using NSUserDefaults

    • Try This: Reading the Settings Bundle

      • Changed Settings While Suspended

    • Summary

  • 15 Property Lists and Archiving

    • An iOS Application’s Directory Structure

      • Directories

    • Property Lists

      • Simple Serialization

    • Try This: Preserving an NSArray

      • NSPropertyListSerialization

    • Try This: Preserving to an XML Property List

    • Archiving

      • Protocols to Adopt

      • NSKeyedArchiver and NSKeyedUnarchiver

    • Try This: Archiving and Unarchiving an Object

    • Try This: Archiving and Unarchiving an Object Hierarchy

      • Multitasking and Saving Application State

    • Summary

  • 16 Data Persistence Using SQLite

    • Adding a SQLite Database

    • Try This: Creating a Simple Database Using FireFox SQLite Manager

    • Basic SQLite Database Manipulation

      • Opening the Database

      • Statements, Preparing Statements, and Executing Statements

      • Select

    • Try This: Opening and Querying a Database

      • SQLite Binding, Inserting, Updating, and Deleting

    • Try This: Inserting, Updating, and Deleting Records

    • Try This: Inserting Records

    • Try This: Updating Records

    • Try This: Deleting Records

    • Summary

  • 17 Core Data

    • Core Data in Brief

    • Creating a Model

      • Entities

      • Attributes

      • Relationships

    • Try This: Adding Entities and Relationships to a Core Data Model

    • Model, Context, and Store

      • NSManagedObjectModel

      • NSPersistentStoreCoordinator

      • NSManagedObjectContext

      • NSManagedObject

    • NSFetchedResultsController

      • NSFetchRequest

      • NSPredicate

      • NSSortDescriptor

    • Try This: Fetching All AKCGroup Entities

    • Adding Objects

    • Saving Changes

    • Deleting Entities

    • Updating Entities

    • Try This: Adding Navigation and AKCGroup Editing

    • Navigation

    • Try This: Adding Navigation and Editing for a List of Breeds

    • Try This: Adding a Breed Detail View

    • Distributing Core Data with Your App

    • What Next?

    • Summary

  • 18 Multimedia

    • Playing Sounds

      • AudioServicesPlaySystemSound

      • AVAudioPlayer and AVAudioPlayerDelegate

    • Try This: Playing a Sound and an MP3

    • Media Player Framework

      • Media Data Classes

      • Selecting Multimedia

      • Playing Multimedia: MPMusicPlayerController

    • Try This: Using the Media Picker and Media Player

      • MPMoviePlayerController

    • Try This: Play a Video

    • Summary

  • 19 Universal Applications for the iPad

    • Creating a Universal Application

    • Try This: Building an App for iPad and iPhone

      • Handling Orientation Changes

    • Try This: Reacting to Orientation Changes

      • Icons and Default Screens

    • Split Views

    • Try This: Add a Split View

    • Other iPad Features

      • Using Popovers for Information or Editing

      • Movies in a View

    • Try This: MoviePlayer Centered on the iPad Screen

      • External Display

      • Working with Documents

    • Summary

  • Index

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • J

    • K

    • L

    • M

    • N

    • O

    • P

    • Q

    • R

    • S

    • T

    • U

    • V

    • W

    • X

    • Y

    • Z

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan