You are previewing Head First iPhone and iPad Development, 2nd Edition.
O'Reilly logo
Head First iPhone and iPad Development, 2nd Edition

Book Description

Have a killer app idea for iPhone and iPad? Head First iPhone and iPad Development will help you get your first application up and running in no time. You'll not only learn how to design for Apple's devices, you'll also master the iPhone SDK tools -- including Interface Builder, Xcode, and Objective-C programming principles -- to create eye-catching, top-selling apps.

Table of Contents

  1. Head First iPhone and iPad Development
  2. Dedication
  3. A Note Regarding Supplemental Files
  4. Advance Praise for Head First iPhone and iPad Development
  5. Praise for other Head First books
  6.  
  7. How to use this Book: Intro
    1. Who is this book for?
    2. Who should probably back away from this book?
      1. We know what you’re thinking
      2. And we know what your brain is thinking
    3. Metacognition: thinking about thinking
      1. Here’s what WE did
    4. Here’s what YOU can do to bend your brain into submission
    5. Read me
      1. System requirements
    6. The technical review team
    7. Acknowledgments
    8. Safari® Books Online
  8. 1. Getting Started: Going Mobile with iOS
    1. So, you want to build an iOS app...
    2. ...‘cause everyone wants one!
      1. Just look at the app store
    3. Apps live in an iTunes universe
    4. Time to make a decision
    5. It all starts with the iOS SDK
    6. Take a look around
    7. Xcode includes app templates to help you get started
    8. Xcode is a full-featured IDE
    9. Xcode is the hub of your iOS project
    10. Build your interface within Xcode
    11. Add the button to your view
    12. The iOS simulator lets you test your app on your Mac
    13. iDecide’s logic
    14. Changing the button text
    15. You’re using the Model View Controller pattern
    16. iDecide is actually a little simpler
      1. This pattern is the secret to iOS development
    17. What happened?
      1. Unless the UI components are hooked up to the code, nothing is going to happen
    18. Use the GUI editor to connect UI controls to code
    19. A component can trigger certain events
      1. Components dispatch events when things happen to them
    20. Connect your events to methods
    21. You’ve built your first iPhone app!
    22. Your iOS Toolbox
      1. Views are constructed in Interface Builder.
      2. Then, you write the code that makes the views work...
      3. ...and connect component events to the code.
      4. The Simulator runs your app virtually.
  9. 2. iOS App Patterns: Hello, Renee!
    1. First, we need to figure out what Mike (really) wants
    2. App design rules—the iOS HIG
      1. Application types
    3. HIG guidelines for pickers and buttons
    4. Create a new View-based project for InstaEmail
    5. The life of a root view
    6. We need data
    7. Use pickers when you want controlled input
    8. Pickers get their data from a datasource...
      1. ...and tell their delegates when something happens
    9. That pattern is back
      1. Controls have their own specific datasources and delegates
      2. Protocols tell you what methods (messages) you need to implement
    10. First, declare that the controller conforms to both protocols
      1. Next, add Mike’s activities and feelings to the implementation file
    11. The datasource protocol has two required methods
    12. Connect the datasource just like actions and outlets
    13. There’s just one method for the delegate protocol
    14. Actions, outlets, and events
    15. Connect the event to the action
    16. Add the IBOutlet and property to your view controller
    17. Next, synthesize the property...
      1. ...and clean up after yourself
    18. Connect the picker to our outlet
    19. Use your picker reference to pull the selected values
    20. Your iOS Toolbox
  10. 3. Objective-C for iOS: Email needs variety
    1. Renee is catching on....
    2. Make room for custom input
    3. Header files describe the interface to your class
    4. Auto-generated accessors also handle memory management
    5. To keep your memory straight, you need to remember just two things
    6. But when Mike’s finished typing...
    7. Customize your UITextField
      1. Change the label on the return key
    8. Components that use the keyboard ask it to appear...
      1. ...and you ask for things by passing messages to other objects
    9. Ask the UITextField to give up focus
    10. Messages in Objective-C use named arguments
    11. Use message passing to tell our View Controller when the Done button is pressed
    12. Where’s the custom note?
      1. Build the email with strings
    13. Your Objective-C Toolbox
  11. 4. Multiple Views: A table with a view
    1. So, how do these views fit together?
    2. The navigation template pulls multiple views together
    3. The table view is built in
    4. A table is a collection of cells
      1. Each drink gets its own temporary cell
    5. Just a few more drinks...
    6. Plists are an easy way to save and load data
      1. Built-in types can save and load from plists automatically
    7. Arrays (and more) have built-in support for plists
    8. Use a detail view to drill down into data
    9. A closer look at the detail view
    10. Use the Navigation Controller to switch between views
    11. Navigation Controllers maintain a stack of View Controllers
      1. Instantiate a View Controller like any other class
    12. Dictionaries store information as key-value pairs
    13. Debugging—the dark side of iOS development
      1. Warnings can help find problems first
    14. First stop on your debugging adventure: the console
    15. Interact with your application while it’s running
      1. And when it’s about to stop running
    16. Xcode supports you after your app breaks, too
    17. The Xcode debugger shows you the state of your application
      1. What the heck is going on?
    18. Your iOS Toolbox
  12. 5. Plists and Modal Views: Refining your app
    1. It all started with Sam...
    2. Use the debugger to investigate the crash
      1. We’re trying to stuff a dictionary into a string
    3. Update your code to handle a plist of dictionaries
    4. The Detail View needs data
    5. The other keys are key
    6. We have a usability problem
    7. Use a disclosure button to show that there are more details available
    8. Sales were going strong
    9. Use Navigation Controller buttons to add drinks
    10. The button should create a new view
    11. We need a view...but not necessarily a new view
    12. The View Controller defines the behavior for the view
    13. A nib file contains the UI components and connections...
      1. ...and information about the nib’s File’s Owner
    14. You can subclass and extend view controllers like any other class
      1. Use Xcode to create a View Controller without a nib
    15. Modal views focus the user on the task at hand...
      1. ...like adding or editing items
    16. Any view can present a modal view
    17. Our modal view doesn’t have a navigation bar
    18. Create the Save and Cancel buttons
    19. Write the Save and Cancel actions
    20. Your iOS Toolbox
  13. 6. Saving, Editing, and Sorting Data: Everyone’s an editor...
    1. Sam is ready to add a Red-Headed School Girl...
    2. ...but the keyboard is in the way
    3. Wrap your content in a scroll view
    4. The scroll view is the same size as the screen
    5. The keyboard changes the visible area
    6. iOS notifies you about the keyboard
    7. Register with the default notification center for events
      1. Then unregister when you’re done
    8. Keyboard events tell you the keyboard state and size
    9. The table view doesn’t know its data has changed
      1. You need to ask the table view to reload its data
    10. The array is out of order, too
      1. Sort your array using NSSortDescriptor
    11. Table views have built-in support for editing and deleting
    12. Your iOS Development Toolbox
      1. Sam has another project in mind...
  14. 7. Migrating to iPad: We need more room
    1. DrinkMixer on the iPad
    2. The iPad simulator
    3. The HIG covers iPads, too
    4. Use Xcode to build your Universal app
    5. Check your devices
    6. Rotation is key with iPad
    7. A persistent view problem
    8. Don’t forget the tableview
      1. Present the popover!
    9. Your iOS Development Toolbox
  15. 8. Tab Bars and Core Data: Enterprise apps
    1. HF bounty hunting
    2. A new iPhone control
    3. Choose a template to start iBountyHunter
    4. There’s a different structure for universal apps
    5. Drawing how iBountyHunter iPhone works...
    6. ...and how it fits with the universal app
    7. Build the fugitive list view
    8. Next up: the Captured view
    9. A view’s contents are actually subviews
    10. After a quick meeting with Bob...
    11. Core Data lets you focus on your app
      1. But wait, there’s more!
    12. Core Data needs to know what to load
      1. We need to define our types
    13. Core Data describes entities with a Managed Object Model
    14. Build your Fugitive entity
      1. Your generated Fugitive class matches the Managed Object Model
      2. NSManagedObject handles storage and memory for generated properties
      3. NSManagedObject also implements the properties
    15. Use an NSFetchRequest to describe your search
      1. Ask the Managed Object Context to fetch data using your NSFetchRequest
    16. Bob’s database is a resource
    17. Back to the Core Data stack
    18. The template sets things up for a SQLite DB
    19. iOS Apps are read-only
    20. The iPhone’s application structure defines where you can read and write
      1. Use the Documents directory to store user data
    21. Copy the database to the Documents directory
    22. Your Core Data Toolbox
  16. 9. Migrating and Optimizing with Core Data: Things are changing
    1. Bob needs documentation
    2. Everything stems from our object model
    3. The data hasn’t been updated
      1. Core Data caught a mismatch between our DB and our model
    4. Data migration is a common problem
    5. Migrate the old data into the new model
      1. Our two models need different versions
    6. Xcode makes it easy to version your data model
    7. Core Data can “lightly” migrate data
    8. Here’s what you’ve done so far...
    9. Bob has some design input
    10. Your app has a lifecycle all its own...
    11. Multitasking rules of engagement
      1. The Managed Object Context saves new or changed items
    12. A quick demo with Bob
    13. Use predicates for filtering data
      1. NSFetchRequest concepts are nearly identical to SQL
    14. We need to set a predicate on our NSFetchRequest
    15. Core Data controller classes provide efficient results handling
      1. Table views and NSFetchedResultsControllers are made for each other
    16. Time for some high-efficiency streamlining
    17. Create the new FetchedResultsController getter method
    18. We need to refresh the data
      1. NSFetchedResultsController can check for changes
    19. Your Data Toolbox
  17. 10. Camera, Map Kit, and Core Location: Proof in the real world
    1. For Bob, payment requires proof
      1. Flip over for the detail view
    2. The way to the camera...
      1. The iPhone isn’t the only device using apps
    3. There’s a method for checking
    4. Prompt the user with action sheets
      1. Use action sheets to let the user pick the image source
    5. Bob needs the where, in addition to the when
    6. Core Location can find you in a few ways
      1. Core Location relies on the LocationManager
    7. Add a new framework
      1. Then update the header file
    8. Just latitude and longitude won’t work for Bob
    9. Map Kit comes with iOS
    10. A little custom setup for the map
    11. Annotations require a little more work finesse
    12. Fully implement the annotation protocol
    13. Your Location Toolbox
  18. 11. iPad UI: Natural interfaces
    1. Bob needs that iPad app, too...
      1. Natural user interfaces make things more real (and easier)
    2. iOS HIG user experience guidelines
      1. It’s about realism and details
    3. Iterate your interface, too
    4. BountyHunterHD is based on a Split View Controller
      1. Pull it all together
    5. Unifying the custom stuff
    6. It seems we have a problem...
      1. ...you can only change things for the entire field!
    7. UIWebview has lots of options
    8. HTML, CSS, and Objective-C
    9. Using UIWebView
      1. Use CSS for the remaining formatting
    10. Your NUI Toolbox
  19. A. Leftovers: The top 4 things (we didn’t cover)
    1. #1. Internationalization and Localization
      1. Localizing nibs
    2. Localizing string resources
      1. Generating your strings file
    3. #2. View animations
      1. Animating table view updates
      2. Animating view and control changes
    4. #3. Accelerometer
      1. All you need is the UIAccelerometer
    5. Understanding device acceleration
    6. #4. A word or two about gaming...
      1. Multi-touch
    7. Quartz and OpenGL
      1. Quartz
      2. OpenGL
      3. Game Kit
  20. B. Preparing an App for Distribution: Get ready for the App Store
    1. Apple has rules
      1. Start at the Apple Developer Portal
      2. First, get your Development Certificate
    2. The Provisioning Profile pulls it all together
    3. Keep track in the Organizer
      1. A few final tips...
  21. Index
  22. About the Authors
  23. Copyright