36,40 €
Join the gold rush to developing cool iPhone apps with thiscomplete iPhone OS 3 developer's guide. Professionaldeveloper Jiva DeVoe speaks your language, and he talks you throughthe entire process--from explaining Cocoa Touch and the iPhoneSDK to using Xcode and the Game Kit API. Follow step-by-steptutorials, then apply practical tips on signing and selling yourapplications. Even if you're new to iPhone developmentyou'll soon be cranking out great code.* Walk through Xcode, Interface Builder, and other key tools* Build simple or complex GUIs with navigation and customviews* Implement a database with Core Data, and design your schema inXcode* Learn to use the iPhone's signature multi-touchcapabilities in your applications* Work with the Apple Push Notification Service* Use the Map Kit API to create apps with embedded maps* Record audio, play video, and access the iPod Library* Set up your developer certificates and code sign your apps* Use Store Kit to sell expanded features and content within yourappsWhether you're a new iPhone developer or seasoned veteran, thisbook is the perfect go-to reference for iPhone development-and oneof an exciting new series for Apple developers.Note: CD-ROM/DVD and other supplementary materials arenot included as part of eBook file.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 472
Veröffentlichungsjahr: 2009
Table of Contents
Part I: Getting Started with the iPhone
Chapter 1: Getting to Know Your Tools
Introducing Xcode
Introducing Interface Builder
Summary
Chapter 2: Building a Basic iPhone Application
Creating a Project from a Template
Building a Simple GUI
Writing a Simple UIViewController
Launching on the iPhone
Summary
Chapter 3: Exploring the Simulator in Depth
Exploring the Simulator UI
Simulating multi-touch
Simulating Core Location
Turning the simulator on its side
Digging deeper into the simulator filesystem
Understanding the Differences between the Simulator and the Real Thing
Avoiding APIs that won't work on a real device
Understanding performance differences
Summary
Part II: Building GUIs
Chapter 4: Understanding the Basics of an iPhone User Interface
Looking at the iPhone Screen
Creating a Cinematic User Experience
Looking at the Built-in Applications
Understanding the Basics of iPhone Navigation
Summary
Chapter 5: Introducing UIViewController
Understanding the Basics of Model, View, Controller
Exploring UIViewController
Overriding Methods on UIViewController
Handling view rotations
Handling memory warnings
Working with UIViewController
Creating the code
Creating the UIViewController header
Creating the UIViewController implementation
Adding the controller to Interface Builder
Understanding the UIApplicationDelegate
Creating the model in the App Delegate
Adding the view to the window
Summary
Chapter 6: Using UITableView
Understanding UITableView Data Sources and Delegates
Understanding NSIndexPath and how it works with UITableViews
Exploring UITableViewDataSource
Exploring UITableViewDelegate
Adding a UITableView to an Application
Making a UITableViewDataSource
Seeing the basic application run
Taking action when a row is touched
Configuring a UITableView to Be Grouped
Adding the state to your model
Updating your UITableViewDataSource
Doing Advanced UITableView Configuration
Adding an alphabetical list to the side
Adding search
Summary
Chapter 7: Working with UITableViewCells
Understanding the Parts of a UITableViewCell
Adding Images to a UITableViewCell
Performing Deeper Customization of UITableViewCells
Thinking about Performance in Custom Cells
Reusing UITableViewCells
Understanding the reuse identifier
Summary
Chapter 8: Working within the UINavigationController Model
Understanding the UINavigationController Navigational Model
Creating a UINavigationController
Configuring a UINavigationController
Pushing and Popping UIViewControllers
Adding a UIToolbar
Allowing Editing of the Rows
Moving MyView into a UINavigationController
Making Your EditViewController
Editing rows
Adding rows
Deleting rows
Summary
Chapter 9: Understanding the UIApplicationDelegate
Exploring the Purpose of the UIApplicationDelegate
Handling Startup and Shutdown
Understanding launch methods
Understanding the applicationWillTerminate method
Receiving Notifications while Your Application Is Running
Handling resource alerts
Handling phone calls and sleep
Changing status
Handling remote notifications
Chapter 10: Applying Custom UIViews
Understanding Cocoa Touch View Geometry
Adding Custom Views to a Project
Implementing the Custom View Code
Working with Core Graphics
Implementing drawRect
Summary
Chapter 11: Handling Touch Events
Handling Touch Events in a Custom UIView
Implementing touchesBegan:withEvent:
Working with the touches NSSet
Implementing touchesMoved:withEvent:
Implementing touchesEnded:withEvent:
Handling multi-touch events
Updating Your Custom View with Touch Events
Moving the circle with a touch
Adding scaling
Summary
Chapter 12: Working with Other Controls
Finding What Other Controls Are Available in Cocoa Touch
Working with a UISlider
Configuring a UISlider through Interface Builder
Updating the status of your UISlider
Using UITabBar
Configuring a UITabBar through Interface Builder
Adding UITabBarItems to a UITabBar
Doing advanced configuration of UITabBars
Using UIPickerView
Configuring UIPickerView through Interface Builder
Creating the UIPickerViewDataSource
Creating a UIPickerView delegate
Summary
Chapter 13: Handling Text Input
Configuring the Keyboard through Interface Builder
Configuring capitalization
Enabling and disabling auto correction
Setting the keyboard type
Setting the behavior of the Return key
Looking at other settings
Working with a Keyboard through Code
Making the keyboard appear
Understanding UITextInputTraits
Handling Events for the Keyboard
Creating a UITextFieldDelegate
Moving your view in response to the keyboard appearance
Summary
Chapter 14: Building Cinematic UIs with Core Animation
Using the UIViews Animation Methods
Using Advanced Core Animation with CALayer
Animating UIImageViews
Summary
Chapter 15: Using OpenGL ES
Understanding the Capabilities of iPhone OpenGL ES
Creating a Very Basic OpenGL View
Summary
Chapter 16: Integrating Safari
Opening URLs Using the iPhone Web Browser
Using UIWebView
Adding a UIWebView to your application
Loading a URL
Implementing a UIWebViewDelegate
Loading HTML content from the application bundle
Summary
Part III: Working with Data
Chapter 17: Storing User Defaults
Acquiring the NSUserDefaults Object
Reading and Writing Values to NSUserDefaults
Setting Your Default Defaults
Using the Settings App
Adding a settings bundle
Adding settings to your settings bundle
Summary
Chapter 18: Implementing a Database with Core Data
Understanding Core Data's Building Blocks
Adding Core Data Support to Favorite Cities
Modifying the app delegate
Working with the Managed Object Model
CRUD — Creating, Reading, Updating, Deleting
Creating
Reading
Updating
Deleting
Bringing it together and updating your app
Understanding What Core Data Makes Easier
Understanding What Core Data Is Not Good For
Summary
Chapter 19: Connecting to the World with Networking
Accessing the Web
Using URLs with foundational classes
Using NSURLRequest and NSURLConnection
Sending E-mail from within Your App with the Message UI Framework
Using Core Foundation Sockets
Exploring CFSocket
Getting host info with CFHost
Using CFStreams
Exploring Bonjour
Browsing for Bonjour services
Using NSNetServices
Summary
Chapter 20: Using the Push Notification Service
Understanding the Push Notification Service Architecture
Understanding the push notification communications
Understanding push notification security
Acquiring Push Notification Certificates
Developing Your Server-Side Push Notification Service
Implementing a Ruby push notification supplier
Pushing notifications
Checking delivery using feedback
Integrating Push Notifications with Your iPhone Client
Registering for notifications
Receiving notifications in your application
Summary
Chapter 21: Using the Game Kit API
Providing Peer-to-Peer Connectivity
Finding peers
Working with sessions
Providing In-Game Voice
Summary
Chapter 22: Implementing Cut, Copy, and Paste
Copying and Pasting with Standard Controls
Understanding Pasteboard Types
Interacting with UIPasteboard
Implementing Cut, Copy, and Paste on a Custom View
Implementing touchesEnded:withEvent: to display the menu
Implementing the copy: method
Implementing the paste: method
Understanding the interactions
Summary
Chapter 23: Using the Maps API
Showing an Embedded Map with MKMapView
Creating an MKMapView
Specifying the map region
Annotating Maps
Thinking about performance with annotations
Converting Coordinates
Summary
Part IV: Working with Media
Chapter 24: Exploring the Supported Media Types
Supported Audio Formats
Compressed audio
Uncompressed audio
Supported Video Formats
Summary
Chapter 25: Playing Audio
Using the AV Foundation Framework
Setting your audio configuration with AVAudioSession
Using an AVAudioSessionDelegate
Playing audio with AVAudioPlayer
Using an AVAudioPlayerDelegate
Playing Audio with OpenAL
Summary
Chapter 26: Accessing the iPod Library
Working with the Media Player Framework
Accessing the Media Library
Using the MPMediaPickerController
Searching for media
Working with Player Controllers
Accessing Media Artwork
Summary
Chapter 27: Recording Audio
Setting up Your AVAudioSession
Allocating an AVAudioRecorder
Creating a Voice Recorder
Summary
Chapter 28: Playing Video in Your Application
Playing Video Files Contained in the App Bundle
Playing Video from the Internet
Summary
Part V: Working with the iPhone Hardware
Chapter 29: Discovering Information about the Device
Accessing the Battery State
Accessing the Proximity Sensor
Working with Device Metadata
Summary
Chapter 30: Getting Your Location Using Core Location
Finding Where You Are
Allocating a CLLocationManager
Setting yourself as the delegate
Implementing the CLLocationManagerDelegate protocol
Starting and stopping location updates
Viewing your location on Google Maps
Narrowing the Accuracy of the Coordinates
Filtering Location Updates
Looking at the Final Code
Working with the iPhone 3GS Compass
Summary
Chapter 31: Working with the Accelerometer
Determining Which Way Is Up
Building a bubble level
Understanding the UIAcceleration object
Capturing Shake Events
Building a “shake to break” detector
Implementing drawRect
Implementing motionBegan and motionEnded
Cancellation of motion events
Summary
Chapter 32: Interfacing with Peripherals
Creating Accessories That Interface with iPhone
Finding Accessories That Are Connected Using EAAccessoryManager
Understanding the EAAccessory Class
Working with EASession
Talking to Your Device Using NSStreams
Summary
Part VI: Handling Distribution
Chapter 33: Code Signing Your Apps
Acquiring a Development Certificate
Understanding the Provisioning Process
Understanding development, distribution, and ad hoc
Installing provisioning profiles
Exploring what happens when an app is signed
Setting up your build to be signed
Doing Ad Hoc Builds
Configuring the build in Xcode
Distributing to users
Summary
Chapter 34: Expanding Your Application Using the In-App Purchase Support
Knowing the Types of Things You Can Sell
Working with Unlockable Content
Setting up Purchasable Content in iTunes Connect
Working with Store Kit
Verifying app purchase availability
Presenting your store
Making the purchase
Processing the payment
Verifying the transaction
Unlocking the content
Restoring purchased content
Understanding In-App Purchasing testing
Summary
Cocoa Touch™ for iPhone® OS 3
Jiva DeVoe
Cocoa Touch™ for iPhone® OS 3
Published byWiley Publishing, Inc.10475 Crosspoint BoulevardIndianapolis, IN 46256www.wiley.com
Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-48107-3
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, 201-748-6011, fax 201-748-6008, or online at http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at (877) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
Library of Congress Control Number: 2009937274
Trademarks: Wiley and the Wiley logo are registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Cocoa Touch and iPhone are trademarks or registered trademarks of Apple, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Cocoa Touch for iPhone OS 3 is an independent publication and has not been authorized, sponsored, or otherwise approved by Apple, Inc.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
For my wife, Dawn, and my children, Robert, Alex, and Izzy. You are, and always will be, the most important people in the world to me.
About the Author
Jiva DeVoe has been writing software for nearly 25 years, starting with his Commodore VIC-20 using BASIC and assembly language, and gradually working his way through C, C++, Python, Ruby, Java, and finally, Objective-C. In 2001, he founded Random Ideas, LLC, a software company dedicated to building great applications for the Mac. When the iPhone SDK was announced, he was honored to be selected as one of the earliest developers to have access to the SDK, and using it, he developed several applications that were available in the iTunes App Store when it launched on July 11, 2008. Since that time, his iPhone applications have received several awards — including being chosen as among the Top 100 apps and games in the App Store — and been featured as Apple Staff Picks and in Apple advertisements. Today, Jiva continues to work full time for his company, developing great iPhone and Mac applications. He lives with his wife, three children, and two basset hounds in the desert of Arizona.
Credits
Acquisitions Editor
Aaron Black
Executive Editor
Jody Lefevere
Project Editor
Martin V. Minner
Technical Editor
Dallas Brown
Copy Editor
Marylouise Wiack
Editorial Director
Robyn Siesky
Editorial Manager
Cricket Krengel
Business Manager
Amy Knies
Senior Marketing Manager
Sandy Smith
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Barry Pruett
Project Coordinator
Katie Crocker
Graphics and Production Specialists
Andrea HornbergerJennifer MayberryMark Pinto
Quality Control Technician
Rebecca Denoncour
Proofreading
Christine Sabooni
Indexing
BIM Indexing & Proofreading
Media Development Project Manager
Laura Moss
Media Development Assistant Project Manager
Jenny Swisher
Preface
My goal in writing this book was to provide a comprehensive toolkit for both new and experienced iPhone developers. Its focus is intended to be primarily on the new technologies of iPhone OS 3, but it includes enough general iPhone development material that even a new developer to the platform will receive a great deal of benefit from reading it.
Writing a book about Cocoa Touch programming is an incredible challenge. It's very difficult to judge the technical capability of the typical reader of a book like this. Does the reader already know Objective-C? Has he or she already been developing for Mac OS X? These are the first questions that I had to ask myself when I began to work on this project.
In the end, I decided that with the development of iPhone OS 3, it was a unique opportunity where the new and experienced reader intersected and therefore, I thought it was an ideal time to write a book that would be useful to them both.
So I decided that this book would contain some introductory material, but that it would primarily focus on the new features of iPhone OS 3. In this way, it provides an excellent bridge for learning the technologies of the new operating system, as well as an introduction to general iPhone development.
As a reader, you are expected to already be somewhat familiar with Objective-C. Additionally, you should be somewhat familiar with either Mac OS X, or iPhone development, though you need not be an expert.
If you're completely new to the platform, I suggest picking up a book specifically on Objective-C to complement this book. There are several such books on the market, but I recommend one that approaches Objective-C from the point of view of learning the core language itself, rather than one that mixes an introduction to Objective-C with other topics. After you've worked through enough of that book to feel comfortable with the syntax of the language, you can begin this book at Chapter 1.
If you've already been developing for Mac OS X, but haven't done any iPhone development, you probably already know Objective-C and are familiar with many of the tools used in iPhone development. However, while iPhone development is similar to Mac OS X development, it's not exactly the same. So I suggest that you skip Chapter 1, and start reading Chapter 2, where you build a basic iPhone app from scratch.
Finally, if you're already an experienced iPhone developer, you already know all the basics involved in iPhone development; you're just here for the iPhone OS 3 material. I suggest you start at Chapter 5. All the chapters were written with the new and updated iPhone OS 3 API in mind, and so even if you are already familiar with UIViewController and friends, you will find new material there.
In these ways, this book provides an excellent extension to your library if you already have books on any of these three subjects.
With regard to conventions used within this book, I've tried to be reasonably consistent, and also tried to generally err on the side of Apple conventions when prudent. The only notable exception has been in my use of the term “method” to indicate functions on instances and classes. Apple generally prefers the term message. This is in part due to the influence of Smalltalk on Objective-C.
Also with regard to method calling conventions, Objective-C is known for being particularly verbose in its method names. As a result, some abbreviation conventions have been adopted when writing about particular methods. I have chosen to follow two standards. The first, I use when the usual use of the method in question is in implementing your own, or in overriding it in a subclass. This is most commonly the case when dealing with delegate methods. In these cases, because it's helpful to know the entire signature of the method, in order to write your own implementation, I have chosen to include the entire method signature. So, for example, these will be written as -(BOOL)foo:(NSString *)bar withBaz:(NSString *)baz. As you can see, in this example, we have a method called foo, which takes two parameters of type NSString *, one called bar and a second called baz, and which returns a BOOL value.
Alternatively, in the case where your typical use will be only to use the method in your own code, since Xcode generally automatically completes the types of the parameters for you, I have chosen to use the abbreviated form of writing the method signatures. In the case of the previous method, that means it's written foo:withBaz:. Notice that wherever a parameter is inserted, a colon holds the place of the parameter.
When referring to keyboard shortcuts, I opted to use the term Command key or the symbol to indicate keyboard shortcuts using the key directly to the left of the space bar on most Apple keyboards. You may also know this as the “Apple” key, as until only a few years ago, it included a small Apple logo on it. Additionally, the key next to the Command key has been called the Option key and the key next to that, the Control key. These should all be consistent with Apple documentation conventions.
When discussing the use of menus in Xcode, I've used the technique of separating the nested menu items using arrow notation. So, to describe the New File sub item of the File menu, it will be written as File⇒New File.
Finally, with regard to sample code, in chapters where I have instructed you to build specific full projects, I have generally tried to include full listings for the code. In cases where I have not, you can always download the projects, complete with artwork and other supporting files, from the book's Web site, located at http://www.wileycom/cocoatouchdevref. There are also chapters where it didn't really make sense to create a full project to demonstrate a technology. In these cases, the code listings are snippets that you can use as a basis for your own code. Because these snippets don't comprise fully functional projects, there will not be example projects for them on the Web site.
I hope that you find this book as enjoyable an experience to read as I had writing it. To me, the mark of a good technical book is that it doesn't sit on my shelf. It holds a place of honor by my desk because I keep returning to it, time and again. I hope that this book holds such prestige in your library, and that it becomes a dog-eared, cover-torn, page-scribbled-on reference that remains useful to you for years to come.
Jiva DeVoe
Acknowledgments
Writing this book has been one of the most challenging and exciting projects I have done in my career, but I could not have done it without the aid and support of some specific individuals whom I would like to thank.
First, I'd like to thank my friend and technical editor, Dallas Brown, of HashBang Industries, who took up the challenge of correcting my mistakes and keeping me honest. Your time spent, and your thoughtful comments were excellent.
Along that same line, I'd also like to thank my friend, Brad Miller, of Cynical Peak Software, who also provided welcome criticism and an extra set of eyes on several chapters, and who always seems to be awake and online at the same times I am.
For pressing forward with the book, even with a tight schedule, I'd like to thank all the folks at John Wiley & Sons. I look forward to working with you on new projects in the future.
For teaching me to marvel at the wonders of technology and encouraging me to pursue my dreams in computers, I'm thankful to my father, Robert A. DeVoe.
Many thanks to my children, who have endured these several months of my working late without complaint. You have earned your trip to Disneyland! It is for you that I do everything I do.
Finally, and most importantly, I'd like to thank my wife, for her unerring support, not just in this project, but in all my work. Without her, this book could not have been finished. You lift me when my spirits are low and tired, and inspire me to keep reaching for new accomplishments and goals. I can't thank you enough.
Part I: Getting Started with the iPhone
Chapter 1
Getting to Know Your Tools
Chapter 2
Building a Basic iPhone Application
Chapter 3
Exploring the Simulator in Depth
Chapter 1: Getting to Know Your Tools
In This Chapter
Becoming familiar with Xcode and Interface Builder
They say that when a craftsman finds a tool that he loves, over time it becomes an extension of him. He learns its idiosyncrasies inside and out, backwards and forwards, and this leads to a relationship that transcends simple use of the tool and instead becomes more involved. The tool becomes an extension of his hand, an extension that he can guide with an almost extrasensory vision.
You are fortunate then, that Apple provides you with an excellent set of free tools for developing software for the iPhone. They are tools that have evolved over the last 15 years of Objective-C development, first on NeXT computers, then on Mac OS X, and now for iPhone.
In this chapter, you will take a brief look at these tools and learn where you can find more information about them. They are incredibly powerful tools that seem to be unique in software development, both for their ability to provide enough power to enable incredibly complex software systems to be developed, and also because they seem to know just when to stay out of your way and simply provide a great text-editing environment for you to write code in.
Unfortunately, a comprehensive description of every last feature of these applications is beyond the scope of this book, and so I won't be delving into them in great detail. My main goal here is simply to introduce you to the tools so that you're familiar with them.
Introducing Xcode
The cornerstone of iPhone software development is the Xcode integrated development environment, or IDE. Xcode originated on NeXT Step computers as Project Builder. Over the years, it has gone through many revisions to finally arrive at the version that is available to you today. It uses GCC as its underlying compiler technology and provides many sophisticated features found in modern IDEs today, such as code completion, re-factoring, and sophisticated code navigation. Interestingly, it also has one of the best cross-platform compiling capabilities of any modern IDE. With it, you can compile for Intel, PowerPC, iPhone OS, or even (with third-party tools) Microsoft Windows. You can do all of this simply by configuring targets in the IDE.
Note
To download Xcode, all you need to do is sign up for a free developer account on the Apple Web site. You can do this at http://developer.apple.com/iphone.
Figure 1.1 shows the main Xcode window. In it, you can see the left panel, which shows the file organization view. From here, you can drag and drop files into your projects or organize them by groups. It also provides the ability to organize your files by Smart groups, which are built using search queries and can be useful for looking for particular files in your projects.
Figure 1.1
The Xcode interface
On the right side, you can see the main editing window. It is in this window that you will do the majority of your programming work. At the top of the text-editing window, you can see some drop-down menus that enable you to quickly jump to any recently opened files. The second drop-down menu from the left enables you to quickly jump to any method in the current file. Holding down the key and using the right and left arrow keys enables you to quickly navigate backwards and forwards through the file history. Additionally, holding down the Option and keys together and pressing the up arrow key enables you to quickly swap between the implementation and header files for the currently active compilation unit.
The Xcode editor is quite sophisticated and can be configured with a variety of shortcuts and hot-keys that make your editing much easier and faster. For example, using the Option key and the right and left arrow keys enables you to quickly jump from word to word in your code. Holding down the key and using the left and right arrow keys enables you to quickly jump to the front or beginning of the current line.
It's a good idea to learn the intricacies of the Xcode editor inside and out, because it is such a fundamental tool to everything that you will be doing as an iPhone OS developer.
Introducing Interface Builder
The second major component of the Xcode programming environment is the graphical user interface (GUI) builder called Interface Builder, shown in Figure 1.2. It is this application that you will use to draw your GUI for your application and connect your buttons to actions in your code.
Many developers coming to iPhone development from other environments are sometimes confused by Interface Builder because it doesn't generate any code. However, this is an asset and not a liability. IDEs that simply generate code tend to be more difficult to work with over time, as the code that they generate becomes out of sync with the user interface. Interface Builder uses more of a metadata style approach. This means that you tell it that you want to instantiate an object of a given type, and when your nib is loaded, it goes and finds the class for that type, instantiates it, and attaches the outlets and actions that you have configured to the appropriate places. It does not serialize actual instances of your objects, nor does it generate code that is compiled.
Note
The files that Interface Builder saves are referred to as nib files. This stands for NeXT Interface Builder. The file extension of the nib files used with the iPhone is .xib. This is to differentiate them as containing XML versus the older, original NeXT format.
I will talk about Interface Builder in a bit more detail in Part II. For now, the important thing to know is that you can start Interface Builder either separately by simply launching it or by double-clicking any of the .xib files in your project.
Figure 1.2
Interface Builder
Summary
In this chapter, I introduced you to Xcode and Interface Builder. In the upcoming chapters, you will use these tools in much more depth, but I wanted to simply give you a brief overview of what they look like so that when you use them in the future you will be familiar with them. I encourage you to read through the documentation on them very carefully and try to become as intimately familiar with them as you can.
Chapter 2: Building a Basic iPhone Application
In This Chapter
Building your first iPhone Application
Using Interface Builder to build a basic GUI for an app
Implementing a very simple UIViewController
Running your basic app on your iPhone
Now that you're a bit more familiar with the tools that you're going to be using for developing on the iPhone, let's look at how to build a very basic iPhone application.
In this chapter, you're going to build a simple iPhone application that will have a text field to display some output and a button to show a small amount of interactivity. When you're finished with this application you will be familiar with the basics of launching an iPhone application from Xcode and running it in the simulator. Additionally, before you're finished, you will run the application on your iPhone to see it running on an actual device.
You begin by choosing one of the templates available from the New Project menu in Xcode.
Creating a Project from a Template
The first thing you'll do to create this basic iPhone application is open up Xcode and go to the New Project menu item, which you will find under the File menu. This presents you with the dialog shown in Figure 2.1. For the purposes of this demonstration, you will choose to create a View-Based Application.
Once you have created this project, Xcode already has files that correspond to the user interface, or UI, for your application, a controller for your view, and various other housekeeping files. It also has preconfigured targets for both the simulator and for a device. The files that are used to define the interface end with an extension of
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!