ebook img

iPhone Programming: The Big Nerd Ranch Guide (Big Nerd Ranch Guides) PDF

476 Pages·2010·20.5 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview iPhone Programming: The Big Nerd Ranch Guide (Big Nerd Ranch Guides)

iPhone Programming The Big Nerd Ranch Guide Joe Conway Aaron Hillegass iPhone Programming: The Big Nerd Ranch Guide by Joe Conway and Aaron Hillegass Copyright © 2010 Big Nerd Ranch, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permis- sion must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recoring, or likewise. For informa- tion regarding permissions, contact Big Nerd Ranch, Inc. 1963 Hosea L. Williams Drive SE Suite 209 Atlanta, GA 30317 (404) 478-9005 http://www.bignerdranch.com/ [email protected] The 10-gallon hat with propeller logo is a trademark of Big Nerd Ranch, Inc. Exclusive worldwide distribution of the English edition of this book by Pearson Technology Group 800 East 96th Street Indianapolis, IN 46240 USA http://www.informit.com ISBN-13 978-0321706249 ISBN-10 0321706242 First printing May 2010 The authors and publisher have taken care in writing and printing this book but make no expressed or implied war- ranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or con- sequential damages in connection with or arising out of the use of the information or programs contained herein. App Store, Apple, Bonjour, Cocoa, Cocoa Touch, Finder, Instruments, Interface Builder, iPad, iPhone, iPod, iPod touch, iTunes, iTunes Store, Keychain, Leopard, Mac, Mac OS, Multi-Touch, Objective-C, Quartz, Snow Leopard, and Xcode are trademarks of Apple, Inc., registered in the U.S. and other countries. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trade- marks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. Acknowledgements While our names appear on the cover, many people helped make this book a reality. We would like to take this chance to thank them. • The other instructors who teach the iPhone Bootcamp fed us with a never-ending stream of suggestions and corrections. They are Scott Ritchie, Brian Hardy, and Alex von Below. • Our tireless editor, Susan Loper, took our distracted mumblings and made them into read- able prose. • Several technical reviewers helped us find and fix flaws. They are Bill Monk, Mark Miller, Alex Silverman, Jonathan Saggau, and Mikey Ward. • Ellie Volckhausen designed the cover. (The photo is of the bottom bracket of a bicycle frame.) • The amazing team at Pearson Technology Group patiently guided us through the busi- ness end of book publishing. The final and most important thanks goes to our students whose questions inspired us to write this book and whose frustrations inspired us to make it clear and comprehensible. PDF: CrUmp 請勿打印此書,若條件許可,請購買。 iPhone Programming: The Big Nerd Ranch Guide Chapter 1. A Simple iPhone Application 1 Creating an Xcode Project 2 Using Interface Builder 4 Model-View-Controller 8 Declarations 10 Declaringmethods 12 Making Connections 12 Settingpointers 13 Settingtargetsandactions 14 Summary 16 Implementing Methods 17 Build and Run on the Simulator 19 Event-driven Programming 20 Application Icons 22 Default Images 24 Chapter 2. Objective-C 26 Using Instances 27 Writing the RandomPossessions Tool 30 NSArrayandNSMutableArray 34 Subclassing an Objective-C Class 36 Accessorsandproperties 40 Instancemethods 42 Initializers 43 self 45 super 46 Initializerchain 47 Classmethods 48 Exceptions and the Console Window 52 Objective-C 2.0 Additions 54 Chapter 3. Memory Management 56 Memory Management Concepts 56 ManagingmemoryinC 57 Managingmemorywithobjects 58 Reference Counting 59 Usingretaincounts 60 Avoidingmemoryleakswithautorelease 62 Managingmemoryinaccessorsandproperties 64 Retaincountrules 65 Managing Memory in RandomPossessions 66 Chapter 4. Delegation and Core Location 73 Delegation 73 Beginning the Whereami Application 77 Usingframeworks 77 CoreLocation 78 ReceivingupdatesfromCLLocationManager 81 Releasing Controller Instance Variables 83 Challenge: Heading 84 For the More Curious: Compiler and Linker Errors 84 For the More Curious: Protocols 86 Chapter 5. MapKit and Text Input 89 Object Diagrams 89 Interface Properties 92 Being a MapView Delegate 94 YourownMKAnnotation 97 Tagginglocations 100 TextInputandtheFirstResponder 101 PuttingthePiecesTogether 103 Challenge: Annotation Extras 105 Challenge: Reverse Geocoding 105 Challenge: Changing the Map Type 105 For the More Curious: Renaming an Application 105 Chapter 6. Subclassing UIView 108 Creating a Custom View 108 ThedrawRect:method 110 InstantiatingaUIView 112 Drawing Text and Shadows 114 Using UIScrollView 115 Zooming 117 Hiding the Status Bar 119 Challenge: Colors 119 For the More Curious: Retain Cycles 119 For the More Curious: Redrawing Views 120 Chapter 7. View Controllers 122 View Controllers and XIB Files 122 Using View Controllers 125 Creating the UITabBarController 126 Creatingviewsfortheviewcontrollers 132 The Lifecycle of a View Controller 139 Challenge: Map Tab 141 For the More Curious: Paging 141 Chapter 8. The Accelerometer 143 Setting Up the Accelerometer 144 Getting Accelerometer Data 145 Orientation and Scale of Acceleration 146 Using Accelerometer Data 146 Smoothing Accelerometer Data 148 Detecting Shakes 148 Challenge: Changing Colors 152 For the More Curious: Filtering and Frequency 152 Chapter 9. Notification and Rotation 155 Notification Center 155 UIDevice Notifications 156 Autorotation 158 For the More Curious: Forcing Landscape Mode 162 Challenge: Proximity Notifications 164 For the More Curious: Overriding Autorotation 164 Chapter 10. UITableView and UITableViewController 166 Beginning the Homepwner Application 167 UITableViewController 167 SubclassingUITableViewController 168 UITableView’s Data Source 173 UITableViewDataSourceprotocol 175 UITableViewCells 178 Reusing UITableViewCells 181 Challenge: Sections 183 Chapter 11. Editing UITableViews 184 Editing Mode 184 Deleting Rows 189 Moving Rows 190 Chapter 12. UINavigationController 198 UINavigationController 199 UINavigationBar 203 An Additional UIViewController 206 The XIB File and File’s Owner 208 SettingupItemDetailViewController 209 Navigating with UINavigationController 211 Appearinganddisappearingviews 217 Challenge: Number Pad 218 Chapter 13. Camera and UIImagePickerController 219 ImageCache: a Singleton 219 NSDictionary 220 TakingpicturesandUIImagePickerController 227 Creatingandusingkeys 232 DismissingtheKeyboard 237 Challenge: Removing an Image 238 For the More Curious: Recording Video 238 Chapter 14. Saving and Loading 242 Application Sandbox 242 Archiving 245 Writing to Disk with NSData 253 Challenge: Archiving Wherewasi 256 For the More Curious: The Application Bundle 258 Chapter 15. Low-Memory Warnings 262 Handling Low-Memory Warnings 262 Simulating Low-Memory Warnings 266 Chapter 16. Subclassing UITableViewCell 268 Creating HomepwnerItemCell 269 Createsubviews 270 Layoutsubviews 272 Usingthecustomcell 273 Image Manipulation 275 Challenge: Accessory Views 281 Challenge: Make it Pretty 281 Chapter 17. Multi-Touch, UIResponder, and Using Instruments 282 Touch Events 282 Creating the TouchTracker Application 283 Turning Touches Into Lines 288 The Responder Chain 290 TheObjectAllocInstrument 292 TheSamplerInstrument 296 Challenge: Saving and Loading 298 Challenge: Circles 298 For the More Curious: UIControl 298 Chapter 18. Core Animation Layer 301 Creating a CALayer 303 For the More Curious: Programmatically Generating Content 312 For the More Curious: Layers and Views 313 Challenge: Dynamic Layer Content 316 Chapter 19. Controlling Animation with CAAnimation 317 Animation Objects 317 Spinning the Time with CABasicAnimation 321 Bouncing the Time with a CAKeyframeAnimation 327 Challenge: More Animation 330 For the More Curious: Presentation and Model Layers 330 Chapter 20. Playing Audio and Video 332 Creating the MediaPlayer Application 332 Playing System Sounds 335 Playing Audio Files 339 Playing Movie Files 341 Low-level APIs 344 Challenge: Audio Recording 344 Chapter 21. Web Services 345 Creating the TopSongs Application 345 Settinguptheinterface 347 Fetching Data From a URL 349 WorkingwithNSURLConnection 350 ParsingXML 353 For the More Curious: The Request Body 358 Challenge: More Data 358 For the More Curious: Credentials 358 Chapter 22. Address Book 361 The People Picker 361 Additions to Possession Class 366 Address Book Functions 368 For the More Curious: That Other Delegate Method 372 Chapter 23. Localization 374 Internationalization using NSLocale 375 Localizing Resources 376 NSLocalizedString and Strings Tables 381 Challenge: Another Localization 384 For the More Curious: NSBundle’s Role in Internationalization 384 Chapter 24. Bonjour 386 Publishing a Service 386 Browsing for Services 388 TXT Record 392 Socket Connections 395 Chapter 25. Settings 398 Settings Bundle 398 NSUserDefaults 402 Registeringdefaults 402 Usingthedefaults 403 Chapter 26. SQLite 405

Description:
Based on Big Nerd Ranch’s popular iPhone Bootcamp class, iPhone Programming: The Big Nerd Ranch Guide leads you through the essential tools and techniques for developing applications for the iPhone, iPad, and iPod Touch. In each chapter, you will learn programming concepts and apply them immediate
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.