Apple Inc. © 2009 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Inc., with the following exceptions: Any person is herebyauthorized to store documentation on a single computer for personal use only and to print copies of documentation for personal use provided that the documentation contains Apple’s copyright notice. The Apple logo is a trademark of Apple Inc. Use of the “keyboard” Apple logo (Option-Shift-K) for commercial purposes without the prior written consent of Apple may constitute trademark infringement and unfaircompetition in violation of federal and state laws. No licenses, express or implied, are granted with respect to any of the technology described in this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-labeled computers. Every efforthas been made to ensure that the information in this document is accurate. Apple is not responsible for typographical errors. Apple Inc. 1 Infinite Loop Cupertino, CA 95014 408-996-1010 Apple, the Apple logo, Cocoa, iPod, Mac, Objective-C, and Xcode are trademarks of Apple Inc., registered in the United States and other countries. Finder and iPhone are trademarks of Apple Inc. Simultaneouslypublished in the United States and Canada.
Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED “AS IS,” AND YOU, THE READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY.
INNO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make anymodification, extension, or addition to this warranty. Some states do not allow the exclusion or limitation of implied warranties or liability for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state.
Introduction 7Organization of This Document 7
Tutorial Overview and Design Patterns 9
Tutorial Overview 9 Design Patterns 10 Delegation 10 Model-View-Controller 10 Target-Action 11
Creating Your Project 13
Xcode 13 Application Bootstrapping 14 Recap 17
Adding a View Controller 19
Adding a View Controller Class 19 Adding a View Controller Property 20 Creating the ViewController Instance 21 Setting Up the View 22 Housekeeping 23 Implementation Source Listing 24 Recap 24
Adding a Nib File 25
Interface Builder 25 Create the Nib File 25 Configuring File’s Owner 28 Connecting the View Outlet 29 Loading the Nib File 30 Recap 30
Configuring the View 31
Adding the User Interface Elements 31 The View Controller Interface Declaration 34Making Connections 35
2009-01-06 | © 2009 Apple Inc. All Rights Reserved.
Recap 37 Chapter 6
Implementing the View Controller 39
The Properties 39 The changeGreeting: Method 39 The Text Field’s Delegate 40 Recap 41
Code and Compiler Warnings 43 Check Connections in the Nib Files 43 Delegate Method Names 43