Home > Store

Core iOS 6 Developer's Cookbook, The, 4th Edition

Register your product to gain access to bonus material or receive a coupon.

Core iOS 6 Developer's Cookbook, The, 4th Edition

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2013
  • Edition: 4th
  • Book
  • ISBN-10: 0-321-88421-3
  • ISBN-13: 978-0-321-88421-3

The Core iOS 6 Developer’s Cookbook brings together reliable, proven solutions for the heart of day-to-day iOS 6 development. World-renowned iOS programming expert Erica Sadun covers all the classes you’ll need to create successful iOS 6 mobile apps with standard APIs and interface elements and take full advantage of iOS 6 graphics, touches, and views.

As in her previous bestselling iOS books, Sadun translates today’s development best practices into working code, distilling key concepts into concise recipes that are easy to understand and transfer into your own projects. This isn’t just cut-and-paste; using her examples, Sadun fully explains both the “how” and “why” of effective iOS 6 development.

All code has been fully revised and extensively tested to reflect the latest iOS 6 features and the newest iPhone, iPad, and iPod touch capabilities. Throughout, every chapter groups related tasks together, so you can jump straight to your solution, without having to identify the right class or framework first. Coverage includes

  • Supporting direct user input through multitouch and gestures, including custom gesture recognizers
  • Building, customizing, and using iOS 6 controls
  • Alerting users via popup dialogs, progress bars, local notifications, popovers, audio pings, and other techniques
  • Assembling views and animation, organizing view hierarchies, and understanding how views work together
  • Using iOS 6’s breakthrough autolayout constraints system to simplify support for multiple screen geometries controlling keyboards, making onscreen elements “text aware,” and efficiently scanning and formatting text
  • Using view controllers to organize your users’ workspaces
  • Managing photos, videos, email, text messages, and iOS 6-enhanced social media updates
  • Implementing VoiceOver accessibility to reach even more users
  • Organizing apps simply and intuitively with tables and adding flexibility with iOS 6’s brand new collection views
  • Getting started with Core Data managed data stores
  • Leveraging iOS 6’s powerful networking and web services support


Downloads

Downloads

To download the code in this book, please visit github.com/erica/iOS-6-Cookbook.

Sample Content

Online Sample Chapter

Core iOS 6 Developer's Cookbook: Gestures and Touches

Sample Pages

Download the sample pages (includes Chapter 1 and Index)

Table of Contents

Preface     xxii

1  Gestures and Touches     1
Touches     1
  Phases     2
  Touches and Responder Methods     3
  Touching Views     4
  Multi-Touch     4
  Gesture Recognizers     5
Recipe: Adding a Simple Direct Manipulation Interface     5
Recipe: Adding Pan Gesture Recognizers     7
Recipe: Using Multiple Gesture Recognizers Simultaneously     9
Resolving Gesture Conflicts     12
Recipe: Constraining Movement     13
Recipe: Testing Touches     15
Recipe: Testing Against a Bitmap     17
Recipe: Drawing Touches Onscreen     19
Recipe: Smoothing Drawings     21
Recipe: Using Multi-Touch Interaction     24
Recipe: Detecting Circles     28
Recipe: Creating a Custom Gesture Recognizer     33
Recipe: Dragging from a Scroll View     35
Recipe: Live Touch Feedback     39
  Enabling Touch Feedback      39
  Intercepting and Forwarding Touch Events     40
  Implementing the TOUCHkit Overlay View     41
Recipe: Adding Menus to Views     44
Summary     46

2  Building and Using Controls     49
The UIControl Class     49
  Target-Action     50
  Kinds of Controls     50
  Control Events     51
Buttons     53
Buttons in Interface Builder     54
  Connecting Buttons to Actions     55
Recipe: Building Buttons     55
  Multiline Button Text     58
  Adding Animated Elements to Buttons     58
  Adding Extra State to Buttons     59
Recipe: Animating Button Responses     59
Recipe: Adding a Slider with a Custom Thumb     61
  Customizing UISlider     62
  Adding Efficiency     63
Appearance Proxies     66
Recipe: Creating a Twice-Tappable Segmented Control     69
  Second-Tap Feedback     70
  Controls and Attributes     70
Working with Switches and Steppers     72
Recipe: Subclassing UIControl     73
  Creating Controls     74
  Tracking Touches     74
  Dispatching Events     74
Recipe: Building a Star Slider     77
Recipe: Building a Touch Wheel     80
Recipe: Creating a Pull Control     83
  Discoverability     83
  Testing Touches     85
Recipe: Building a Custom Lock Control     87
Adding a Page Indicator Control     90
Recipe: Creating a Customizable Paged Scroller     93
Building Toolbars     98
Summary     100

3  Alerting the User     101
Talking Directly to Your User Through Alerts     101
  Building Simple Alerts     102
  Alert Delegates     103
  Displaying the Alert     104
  Kinds of Alerts     104
“Please Wait”: Showing Progress to Your User     105
  Using UIActivityIndicatorView     106
  Using UIProgressView     107
Recipe: No-Button Alerts     107
  Building a Floating Progress Monitor     109
Recipe: Creating Modal Alerts with Run Loops     110
Recipe: Using Variadic Arguments with Alert Views     113
Presenting Lists of Options     114
  Scrolling Menus     117
  Displaying Text in Action Sheets     117
Recipe: Building Custom Overlays     117
  Tappable Overlays     119
Recipe: Basic Popovers     119
Recipe: Local Notifications     121
  Best Practices     122
Alert Indicators     123
  Badging Applications     124
Recipe: Simple Audio Alerts     124
  System Sounds     124
  Vibration     125
  Alerts     126
  Delays     126
  Disposing of System Sounds     126
Summary     128

4  Assembling Views and Animations     129
View Hierarchies     129
Recipe: Recovering a View Hierarchy Tree     131
  Exploring XIB and Storyboard Views     132
Recipe: Querying Subviews     133
Managing Subviews     134
  Adding Subviews     134
  Reordering and Removing Subviews     135
  View Callbacks     135
Tagging and Retrieving Views     136
  Using Tags to Find Views     136
Recipe: Naming Views by Object Association     137
  Naming Views in Interface Builder     137
View Geometry     139
  Frames     140
  Rectangle Utility Functions     140
  Points and Sizes     141
  Transforms     142
  Coordinate Systems     142
Recipe: Working with View Frames     143
  Adjusting Sizes     144
  CGRects and Centers     146
  Other Geometric Elements     147
Recipe: Retrieving Transform Information     151
  Retrieving Transform Properties     151
  Testing for View Intersection     152
Display and Interaction Traits     157
UIView Animations     158
  Building Animations with Blocks     159
Recipe: Fading a View In and Out     159
Recipe: Swapping Views     161
Recipe: Flipping Views     162
Recipe: Using Core Animation Transitions     163
Recipe: Bouncing Views as They Appear     165
Recipe: Image View Animations     166
Summary     167

5  View Constraints     169
What Are Constraints?     169
Alignment Rectangles     170
  Declaring Alignment Rectangles     171
Constraint Attributes     171
  Constraint Math     172
The Laws of Constraints     173
Creating Constraints     175
  Basic Constraint Declarations     175
  Visual Format Constraints     176
  Variable Bindings     177
Format Strings     177
  Orientation     177
  View Names     179
  Connections     179
Predicates     183
  Metrics     183
  View-to-View Predicates     184
  Priorities     184
Format String Summary     184
Storing and Updating Constraints     186
Recipe: Comparing Constraints     187
Recipe: Describing Constraints     189
Recipe: Creating Fixed-Size Constrained Views     192
  Disabling Autosizing Constraints     192
  Starting within View Bounds     193
  Constraining Size     193
Recipe: Centering Views     196
Recipe: Setting Aspect Ratio     197
Aligning Views and Flexible Sizing     199
  Why You Cannot Distribute Views     199
Recipe: Responding to Orientation Changes     200
Constraint Macros     202
  Consistent Constraints     202
  Sufficient Constraints     203
  Macros     203
Debugging Your Constraints     205
Summary     207

6  Text Entry     209
Recipe: Dismissing a UITextField Keyboard     209
  Preventing Keyboard Dismissal     210
  Text Trait Properties     211
  Other Text Field Properties     212
Recipe: Dismissing Text Views with Custom Accessory Views     213
Recipe: Adjusting Views Around Keyboards     216
Recipe: Adjusting Views Around Accessory Views     220
  Testing for Hardware Keyboards     221
Recipe: Creating a Custom Input View     223
Recipe: Making Text-Input-Aware Views     227
Recipe: Adding Custom Input Views to Nontext Views     230
  Adding Input Clicks     231
Recipe: Building a Better Text Editor (Part I)     233
Recipe: Building a Better Text Editor (Part II)     236
  Enabling Attributed Text     236
  Controlling Attributes     236
  Other Responder Functionality     237
Recipe: Text-Entry Filtering     239
Recipe: Detecting Text Patterns     242
  Rolling Your Own Expressions     242
  Enumerating Regular Expressions     243
  Data Detectors     243
  Using Built-In Type Detectors     244
  Useful Websites     244
Recipe: Detecting Misspelling in a UITextView     246
Searching for Text Strings     247
Summary     248

7  Working with View Controllers     249
View Controllers     249
  The UIViewController Class     250
  Navigation Controllers     250
  Tab Bar Controllers     251
  Split View Controllers     251
  Page View Controller     251
  Popover Controllers     251
Developing with Navigation Controllers and Split Views     252
  Using Navigation Controllers and Stacks     253
  Pushing and Popping View Controllers     254
  Bar Buttons     254
Recipe: The Navigation Item Class     255
   Titles and Back Buttons     255
  Macros     256
Recipe: Modal Presentation     257
  Presenting a Custom Modal Information View     258
Recipe: Building Split View Controllers     261
Recipe: Creating Universal Split View/Navigation Apps     266
Recipe: Tab Bars     268
Remembering Tab State     272
Recipe: Page View Controllers     275
  Book Properties     276 
  Wrapping the Implemen  tation     277
  Exploring the Recipe     279
  Building a Presentation Index     279
Recipe: Scrubbing Pages in a Page View Controller     285
Recipe: Custom Containers     286
  Adding and Removing a Child View Controller     287
  Transitioning Between View Controllers     288
Recipe: Segues     292
  Segues, Interface Builder, and iOS 6     297
Summary     298

8  Common Controllers     299
Image Picker Controller     299
  Image Sources     299
  Presenting the Picker on iPhone and iPad 300
Recipe: Selecting Images     300
  How To: Adding Photos to the Simulator     301
  The Assets Library Framework     301
  Presenting a Picker     302
  Handling Delegate Callbacks     303
Recipe: Snapping Photos     306
  Setting Up the Picker     307
  Displaying Images     308
  Saving Images to the Photo Album     309
Recipe: Recording Video     310
  Creating the Video Recording Picker     311
  Saving the Video     311
Recipe: Playing Video with Media Player     313
Recipe: Editing Video     316
  AV Foundation and Core Media     316
Recipe: Picking and Editing Video     318
Recipe: E-Mailing Pictures     321
  Creating Message Contents     321
Recipe: Sending a Text Message     323
Recipe: Posting Social Updates     325
Recipe: Activity View Controller     328
  Creating and Presenting the Controller     328
  Adding Services     331
I  tems and Services     335
Recipe: The Quick Look Preview Controller     336
  Implementing Quick Look     337
Summary     340

9  Accessibility     341
Accessibility 101      341
  Accessibility in Interface Builder     342
Enabling Accessibility     343
Traits     344
Labels     345
Hints     346
Testing with the Simulator     347
Broadcasting Updates     348
Testing Accessibility on the iPhone     349
Summary     351

10  Creating and Managing Table Views     353
iOS Tables     353
Delegation     354
Creating Tables     355
  Table Styles     355
  Laying Out the View     355
Assigning a Data Source     356
Serving Cells     356
Registering Cell Classes     356
Dequeueing Cells     357
Assigning a Delegate     357
Recipe: Implementing a Basic Table     358
Data Source Methods     359
Responding to User Touches     359
Table View Cells     361
Selection Color     362
Adding in Custom Selection Traits     363
Recipe: Creating Checked Table Cells     363
Working with Disclosure Accessories     365
Recipe: Table Edits     367
Adding Undo Support     368
Supporting Undo     369
Displaying Remove Controls     369
Handling Delete Requests     369
Swiping Cells     370
Reordering Cells     370
Adding Cells      370
Recipe: Working with Sections     375
Building Sections      375
Counting Sections and Rows     376
Returning Cells     377
Creating Header Titles     378
Customizing Headers and Footers     379
Creating a Section Index     379
Handling Section Mismatches     380
Delegation with Sections     380
Recipe: Searching Through a Table     382
Creating a Search Display Controller     383
Registering Cells for the Search Display Controller     384
Building the Searchable Data Source Methods     384
Delegate Methods     385
Using a Search-Aware Index     386
Recipe: Adding Pull-to-Refresh to Your Table     388
Recipe: Adding Action Rows     391
Coding a Custom Group Table     394
  Creating Grouped Preferences Tables     395
Recipe: Building a Multiwheel Table     396
  Creating the UIPickerView     397
  Data Source and Delegate Methods     397
  Using Views with Pickers     397
Using the UIDatePicker     399
  Creating the Date Picker     400
Summary     401

11  Collection Views     403
Collection Views Versus Tables     403
  Practical Implementation Differences     405
Establishing Collection Views     405
  Controllers     405
  Views     406
  Data Sources and Delegates     406
Flow Layouts     407
  Scroll Direction     407
  Item Size and Line Spacing     407
  Header and Footer Sizing     409
  Insets     410
Recipe: Basic Collection View Flows     411
Recipe: Custom Cells     415
Recipe: Scrolling Horizontal Lists     416
Recipe: Introducing Interactive Layout Effects     420
Recipe: Scroll Snapping     422
Recipe: Creating a Circle Layout     423
  Creation and Deletion Animation     424
  Powering the Circle Layout     424
  The Layout     425
Recipe: Adding Gestures to Layout     429
Recipe: Creating a True Grid Layout     431
Recipe: Custom Item Menus     437
Summary     439

12  A Taste of Core Data     441
Introducing Core Data     441
Entities and Models     442
  Building a Model File     442
  Attributes and Relationships     443
  Building Object Classes     444
Creating Contexts     444
Adding Data     445
  Examining the Data File     446
Querying the Database     448
  Setting Up the Fetch Request     449
  Performing the Fetch     449
Removing Objects     450
Recipe: Using Core Data for a Table Data Source     451
  Index Path Access     451
  Section Key Path     451
  Section Groups     452
  Index Titles     452
  Table Readiness     452
Recipe: Search Tables and Core Data     455
Recipe: Adding Edits to Core Data Table Views     457
  Adding Undo/Redo Support     458
  Creating Undo Transactions     459
  Rethinking Edits     459
Recipe: A Core Data-Powered Collection View     464
Summary     469

13  Networking Basics     471
Recipe: Checking Your Network Status     471
Scanning for Connectivity Changes     474
Recipe: Synchronous Downloads     476
Recipe: Asynchronous Downloads     480
One-Call No-Feedback Asynchronous Downloads     486
Recipe: Using JSON Serialization     487
Recipe: Converting XML into Trees     489
  Trees         489
  Building a Parse Tree      490
Summary     492
Appendix Objective-C Literals     495
Numbers     495
Boxing     496
  Enums     496
Container Literals     497
Subscripting     498
Feature Tests     499
Index     501

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020