684 programming iOS 5, 2nd edition covers iOS 5 and xcode 4 3

1,014 103 0
  • Loading ...
    Loading ...
    Loading ...

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Tài liệu liên quan

Thông tin tài liệu

Ngày đăng: 06/03/2019, 14:39

www.it-ebooks.info www.it-ebooks.info SECOND EDITION Programming iOS Matt Neuburg Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo www.it-ebooks.info Programming iOS 5, Second Edition by Matt Neuburg Copyright © 2012 Matt Neuburg All rights reserved Printed in the United States of America Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472 O’Reilly books may be purchased for educational, business, or sales promotional use Online editions are also available for most titles (http://my.safaribooksonline.com) For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com Editor: Brian Jepson Production Editor: Kristen Borg Proofreader: O’Reilly Production Services March 2012: Indexer: Matt Neuburg Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Matt Neuburg Second Edition Revision History for the Second Edition: 2011-12-23 Early release 2012-03-12 First release See http://oreilly.com/catalog/errata.csp?isbn=9781449319342 for release details Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc Programming iOS 5, the image of a kingbird, and related trade dress are trademarks of O’Reilly Media, Inc Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein ISBN: 978-1-449-31934-2 [M] 1331571373 www.it-ebooks.info Table of Contents Preface xvii Part I Language Just Enough C Compilation, Statements, and Comments Variable Declaration, Initialization, and Data Types Structs Pointers Arrays Operators Flow Control and Conditions Functions Pointer Parameters and the Address Operator Files The Standard Library More Preprocessor Directives Data Type Qualifiers 10 13 14 16 20 23 25 27 28 29 Object-Based Programming 31 Objects Messages and Methods Classes and Instances Class Methods Instance Variables The Object-Based Philosophy 31 32 33 36 37 38 Objective-C Objects and Messages 43 An Instance Reference Is a Pointer Instance References, Initialization, and nil 43 44 iii www.it-ebooks.info Instance References and Assignment Instance References and Memory Management Messages and Methods Sending a Message Declaring a Method Nesting Method Calls No Overloading Parameter Lists Unrecognized Selectors Typecasting and the id Type Messages as Data Type C Functions CFTypeRefs Blocks 47 49 49 50 51 52 53 53 54 56 59 60 62 63 Objective-C Classes 67 Class and Superclass Interface and Implementation Header File and Implementation File Class Methods The Secret Life of Classes 67 69 71 73 74 Objective-C Instances 77 How Instances Are Created Ready-Made Instances Instantiation from Scratch Nib-Based Instantiation Polymorphism The Keyword self The Keyword super Instance Variables and Accessors Key–Value Coding Properties How to Write an Initializer 77 77 78 81 82 84 86 89 91 91 94 Part II IDE Anatomy of an Xcode Project 99 New Project The Project Window The Navigator Pane The Utilities Pane 100 101 103 107 iv | Table of Contents www.it-ebooks.info The Editor The Project File and Its Dependents The Target Build Phases Build Settings Configurations Schemes and Destinations From Project to App Build Settings Property List Settings Nib Files and Storyboard Files Other Resources Code Frameworks and SDKs 109 111 114 114 115 117 118 120 122 122 123 124 126 128 Nib Management 133 A Tour of the Nib-Editing Interface The Dock Canvas Inspectors and Libraries Nib Loading and File’s Owner Making and Loading a Nib Outlet Connections More Ways to Create Outlets More About Outlets Action Connections Additional Initialization of Nib-Based Instances 134 135 136 138 140 142 143 148 150 151 155 Documentation 157 The Documentation Window Class Documentation Pages Sample Code Other Resources Quick Help Symbols Header Files Internet Resources 158 159 163 164 164 165 165 166 Life Cycle of a Project 169 Choosing a Device Architecture Localization Editing Your Code Autocompletion 169 173 174 175 Table of Contents | v www.it-ebooks.info Snippets Live Syntax Checking and Fix-it Navigating Your Code Debugging Caveman Debugging The Xcode Debugger Unit Testing Static Analyzer Clean Running in the Simulator Running on a Device Device Management Version Control Instruments Distribution Ad Hoc Distribution Final App Preparations Icons in the App Other Icons Launch Images Screenshots Property List Settings Submission to the App Store 176 177 177 180 180 183 188 189 189 190 192 196 196 198 202 204 206 206 207 208 209 209 211 Part III Cocoa 10 Cocoa Classes 217 Subclassing Categories Splitting a Class Private Method Declarations Protocols Optional Methods Some Foundation Classes Useful Structs and Constants NSString and Friends NSDate and Friends NSNumber NSValue NSData Equality and Comparison NSIndexSet vi | Table of Contents www.it-ebooks.info 217 220 221 222 223 227 229 229 230 232 232 233 233 234 234 NSArray and NSMutableArray NSSet and Friends NSDictionary and NSMutableDictionary NSNull Immutable and Mutable Property Lists The Secret Life of NSObject 235 236 237 239 239 240 240 11 Cocoa Events 245 Reasons for Events Subclassing Notifications Receiving a Built-In Notification Unregistering NSTimer Delegation Data Sources Actions The Responder Chain Deferring Responsibility Nil-Targeted Actions Application Lifetime Events Swamped by Events 246 246 248 249 251 253 253 257 258 263 264 264 265 270 12 Accessors and Memory Management 275 Accessors Key–Value Coding Memory Management Principles of Cocoa Memory Management The Golden Rules of Memory Management What ARC Is and What It Does How Cocoa Objects Manage Memory Autorelease Memory Management of Instance Variables (Non-ARC) Memory Management of Instance Variables (ARC) Retain Cycles and Weak References Nib Loading and Memory Management Memory Management of Global Variables Memory Management of Pointer-to-Void Context Info Memory Management of CFTypeRefs Properties 275 277 281 281 282 285 288 290 293 297 299 306 307 308 310 313 Table of Contents | vii www.it-ebooks.info 13 Data Communication 319 Model–View–Controller Instance Visibility Visibility by Instantiation Visibility by Relationship Global Visibility Notifications Key–Value Observing 319 321 322 323 324 325 327 Part IV Views 14 Views 335 The Window Subview and Superview Frame Bounds and Center Layout Transform Visibility and Opacity 335 338 341 343 346 349 353 15 Drawing 355 UIImage and UIImageView Graphics Contexts UIImage Drawing CGImage Drawing CIFilter and CIImage Drawing a UIView Graphics Context Settings Paths and Drawing Clipping Gradients Colors and Patterns Graphics Context Transforms Shadows Points and Pixels Content Mode 355 359 363 364 367 370 372 373 377 378 380 382 384 385 385 16 Layers 389 View and Layer Layers and Sublayers Manipulating the Layer Hierarchy Positioning a Sublayer viii | Table of Contents www.it-ebooks.info 390 392 393 394 memory management, golden rules of, 284 memory, low, 270, 565 memory, releasing, 566, 568 menus, 951 menus in a table view, 646 menus in a text field, 683 message, 32 action message, 151 dynamic message sending, 54, 228 receiver, 50 selector, 60 message as data, 59 message forwarding, 741 message sending syntax, 50 message to nil, 46 Message UI framework, 845 message vs method, 33 method, 33 calling a method, 50 nesting method calls, 52 class method, 36, 73 colons in method name, 50 conflicting signatures, 59 current method, logging, 182 declaring a method, 51, 70 declaring a method privately, 222 defining a method, 69 factory method, 36, 74 global utility method, 74 inheritance, 68, 82 instance method, 36 minus sign (instance method), 36, 51 optional methods, 227 overriding, 68, 87 parameter, 50 parameter lists, 53 plus sign (class method), 36, 51 signature of a method, 53, 59 method naming conventions and ARC, 287 method not found, 54 method vs message, 33 MFMailComposeViewController, 845 MFMessageComposeViewController, 846 Microsoft Office, 697 MIDI files, 778 minus sign (instance method), 36, 51 misaligned images, 192, 346 missing base SDK, 163 missing sentinel, 54 mixin classes, 223 MKAnnotation protocol, 850 MKAnnotationView, 850 MKMapRect, 848 MKMapView, 847, 865 MKOverlay protocol, 856 MKOverlayView, 856 MKUserTrackingBarButtonItem, 866 Mobile Core Services framework, 809 modal dialogs, 747 action sheet, 750 alert view, 748, 756 local notifications, 756 modal dialogs, alternatives to, 754 modal popovers, 657 modal view controller, 498, 526 modal view in a popover, 657 modal views, 526 model–view–controller, 319 More item in tab bar, 540, 739 motion manager, 876 motion of device, 876 movies (see video) MPMediaEntity, 797 MPMediaLibrary, 801 MPMediaPickerController, 806 MPMoviePlayerController, 782 MPMoviePlayerController requires prepareToPlay, 782 MPMoviePlayerViewController, 788 MPMusicPlayerController, 801 multiple cell selection, 623 multiple methods found with mismatched result, 59 multitasking, 266 multitouch sequence, 464 multivalue, 824 Music app, 797 Music app, controlling and querying, 802 Music app, default remote control event target, 774 music library, 797 mutability of instances, 48 mutable, 239 mutable array, observing, 329 MVC, 319 N namespaces, 73 972 | Index www.it-ebooks.info naming accessors, 275 navigating your code, 177 navigation bar, 540, 734 navigation bar contents, configuring, 546 navigation bar, customizing, 735 navigation bar, hiding and showing, 551 navigation bar, left item with back item, 735 navigation bar, multiple buttons, 735 navigation controller, 541 navigation interface, 541, 625 navigation interface, configuring, 549 navigation item, 541, 546, 734 Navigator pane, 103 navigators Breakpoint navigator, 107 Debug navigator, 105, 185 Issue navigator, 104 Log navigator, 107 Project navigator, 103, 178 Search navigator, 104 Symbol navigator, 104, 178 nesting method calls, 52 network activity in status bar, 708 new, 80 NeXTStep, 43, 133 nib files, 81, 123 class of object in nib, changing, 138 creating a nib file, 142 loading a nib file, 140, 142 main nib, 123, 127 nib objects, 135 owner of nib file, 140 proxy objects, 135 top-level objects, 135 nib name matching view controller, 512 nib objects, 135 nib-based instantiation, 81, 141 nib-based instantiation and memory management, 306 nib-instantiated view controller, 515 nib-loaded cells, 605 nib-loaded view of view controller, 511 nil, 19, 45 message to nil, 46 nil in collections illegal, 239 nil terminator, forgetting, 54 nil testing, 45 nilifying, 285 release by nilifying, 298 nilifying unsafe references, 301 nilifying, automatic by ARC, 285 NO, 20 no known instance method for selector, 57 nonatomic, 315 Notification Center, 756 notifications, 248 registering for a notification, 249 unregistering for a notification, 251, 302 notifications and retain cycles, 302 notifications matching delegate methods, 255 notifications, local, 756 notifications, when appropriate, 325 now-playing interface, 775 NS prefix, 43 NSArray, 235 NSArray proxy, key–value coding, 280 NSAttributedString, 688 NSCoding, 890 NSCopying, 224 NSData, 233 NSDate, 232 NSDateFormatter, 232, 722 NSDictionary, 237 NSError, 23, 46 NSFileManager, 889 NSIndexSet, 234 NSInteger, NSInvocation, 950 NSKeyedArchiver, 890 NSKeyedUnarchiver, 890 NSLinguisticTagger, 231 NSLog, 180 NSNetServiceBrowser, 923 NSNotFound, 230 NSNotification, 248 NSNotificationCenter, 248 NSNull, 239 NSNumber, 232 NSObject, 69, 240–243 NSObject documentation scattered, 241 NSOperation, 935 NSOperationQueue, 935 NSOrderedSet, 237 NSPredicate, 236 NSRange, 229 NSRegularExpression, 230 NSScanner, 230 NSSet, 236 Index | 973 www.it-ebooks.info NSString, 230 CFString vs NSString, 62 concatenating literal strings, date to string conversion, 722 drawing an NSString, 672 escaped characters, literal NSString, Unicode characters, NSString literal directive, NSThread, 934 NSTimer, 253 NSUndoManager, 947 NSURLConnection, 915 NSURLRequest, 698, 915 NSUserDefaults, 324, 891 NSValue, 233 NSXMLParser, 905 NULL, 62 outlet broken by misused accessor name, 276 outlet collections, 150 outlet connections, 143, 276 outlet, forgetting to connect, 148 outlets, 143 overlapping views, 339 overlay (on map), 856 overloading, 53 overriding, 68, 87 overriding a synthesized accessor, 317 owner of nib file, 140 P O object, 31 Object library, 108, 137 object-based programming, 31 object-oriented programming, 86 Objective-C, 3, 43–95, 220–229 Objective-C 2.0, 90, 91 Objective-C is C, forgetting, Objective-C, history of, 43 opaque, 354, 371, 399 opaque graphics context, 375 operation queues, 935 operators address operator, 23, 61 arithmetic operators, 14 arrow operator, 90 bitwise operators, 14 decrement operator, 14 equality operator, 19 increment operator, 14 logical operators, 18 relational operators, 18 sizeof operator, 24 structure pointer operator, 90 ternary operator, 15 optimizing, 199 optional directive, 224 optional methods, 227 orientation of device, 519 orientation of interface at startup, 523 page control, 719 page view controller, 551 paging, 576 parameter, 20, 50 parameter lists, 53 parent view controller, 498 parent view controller vs presenting view controller, 526 parent view controller, custom, 554 parentheses around condition, forgetting, 16 passing to parameter of incompatible type, 225 password field, 681 pasteboard, 685 path, 373 path, compound, 374 patterns, 380 PDF, 697 phases of a touch, 464 photo assets and albums creatable, 820 photo library, 809 photo, taking, 812 Photos app, 809 picker view, 711 pixels vs points, 385 pixels, transparent, 488 Plato, 34 plus sign (class method), 36, 51 pointer to class name, 43 pointer to function, 61 pointer to pointer to NSError, 23, 46 pointer to struct (see CFTypeRef) pointer-to-void, 11 pointer-to-void, memory management of, 308 pointers, 10 assignment to a pointer, 11, 47 974 | Index www.it-ebooks.info creating a pointer, 23 dangling pointers, 282 declaring a pointer, 10 dereferencing a pointer, 11 garbage pointer, 45 generic pointer, 11 indirection, 24 memory management, 49 nilifying, 285 reference to an instance, 23 points vs pixels, 385 polar coordinates, 732 polymorphism, 82–86 pool, autorelease, 291, 933 popovers, 649–663, 750–754 popovers, automatic, 661 popovers, customizing appearance, 653 popovers, dismissing, 656, 657 popovers, presenting, 651 popovers, rotation and, 656 popovers, size of, 651 popovers, storyboard and, 660 Portal, iOS Provisioning, 192 position of a sublayer, 394 position of a subview, 341 posting a notification, 248 pragma directive, 29, 178 precompiled header, 128 preprocessing, define directive, 28 import directive, 26 include directive, 25 pragma directive, 29 warning directive, 29 presentation context, 533 presentation layer, 417, 489 presented view controller, 499, 526 presented view controllers and rotation, 534 presented view, animation of, 531 presented view, what view it replaces, 532 presenting action sheet clipped by its superview, 751 presenting and presented view controllers, communication between, 529 presenting view controller, 526 previewing a document, 897 private methods, 222 private properties, 317 product name, 100 profiling, 198 progress view, 708 progress view, animation, 709 progress view, colors and images, 709 project, 99 project file, 111 project folder, 111 Project navigator, 103, 178 groups, 113 project templates, 100 Empty Application, 338 main window, 336 Master–Detail Application, 625, 665 Single View Application, 336, 498, 514 Tabbed Application, 540 Utility Application, 227, 257 project window, 102 project, renaming, 131 properties, 91, 313–318 properties, animatable, 430 properties, custom animatable, 440 property list settings, 122, 210 property lists, 240 protected, 89, 276 protocol directive, 224 protocol documentation, forgetting, 256 protocols, 223 protocols documented separately, 226 proxy objects, 135 push notifications, 925 Q QLPreviewController, 898 qualifiers, 29 Quartz Core framework, 390, 413 questions, three big, 612 queues, dispatch, 940 queues, dispatch, concurrent, 943 queues, operation, 935 queues, serial, 938 Quick Help, 108, 164 Quick Look framework, 898 quotation marks in import directive, 27 R random function, 28 reading a file, 890 readonly, 315 Index | 975 www.it-ebooks.info receiver, 50 receiver type for instance message does not declare method, 55 rectangle, rounded, 377, 409 redisplaying a layer, 397, 399 redraw moment, 414 redrawing with animation, 424, 428, 445 Ref suffix, 63 refactoring, 180 Refactoring (book), 41 reference to an instance, 23, 43 reference, getting, 33, 321 reference, getting, to a UIPopoverController, 656, 663 reference, unsafe, 301 reference, weak, 300 region monitoring, 871 registering for a notification, 249 regular expressions, 230 relational operators, 18 relationships, 557 relationships between instances, built-in, 323 release, 284 release by nilifying, 298 remote control of audio, 773 remote notifications, 925 renaming a project, target, or symbol, 131 replace, 180 resizable image, 357 resolution, 356, 366, 577 resources, 124 resources in your app bundle, 356 resources that differ on iPad, 172, 356 responder, 263 responder chain, 263, 493 responder chain includes app delegate, 263 responders and touches, 493 restricting touches, 467, 491 retain, 284 retain count, 282 retain cycle, 299 retains, unusual, 305 Retina display (see screen, double resolution) return, 21 Ritchie, Dennis, root class, 67 root view, 136, 336, 498 root view controller, 338, 498, 500 root view controller, app without, discouraged, 338 rotating a drawing, 383 rotating interface, 519–526, 534, 537, 544 rotation, 523 (see also orientation) rotation 3D transform, 405 rotation and bar height, 736 rotation and navigation controllers, 544 rotation and page view controllers, 554 rotation and popovers, 656 rotation and presented view controllers, 534 rotation and split view controllers, 666 rotation and tab bar controllers, 537 rounded rectangle, 377, 409 routing of audio, 769 RTF, 697 run, 101 run loop, 928 running on a device, 192 runtime environment, testing for, 171, 808 S sandbox, 887 Saved Photos album, 819 saving state, 269, 892 saving to a file, 890, 900 scene, 518, 557 schemes, 118 scope in flow control, 16 scope in function definition, 21 screen coordinates, 343 screen, double resolution, 356, 366, 577 screen, user locks or unlocks, 268 screens, multiple, 336 screenshots, 209 scroll indicators, 574 scroll view deceleration, stopping point, 585 scroll view gesture recognizers, 590 scroll view of a web view, 697 scroll views, 569–592 content of scroll view, 569 delegate of a scroll view, 584 paging, 576 scrolling, 573 tiling, 577 touches in a scroll view, 587 zooming, 579 scrolling, 573 976 | Index www.it-ebooks.info scrolling in response to keyboard, 677 scrolling with CATiledLayer, 577 SDK, 128 search bar, 713 search bar in a toolbar, 662, 716 search bar, customizing, 713 Search navigator, 104 search results in table view, 630, 662 searching for symbols, 165 searching the documentation, 158 searching your code, 179 sections of a table view, 616 sections of a table view, collapsing, 645 segmented control, 725 segmented control, customizing, 726 segue, 518, 557 segue, popover, 660 SEL, 60 selection in a table view, 623 selection in a text view, 686 selector, 55, 60 selector directive, 60 self, 84 self retained by block, 304 semicolon, forgetting, sending a message, 50 sentinel, 54 separators in table views, 602 serial queues, 938 set, 237 setter, 275 Settings app, 893 settings bundle, 893 shadows, 384, 409 shaking the device, 874, 951 shape layers, 402 shapes, hit-testing of, 487 shared application instance, 78, 127 shared data, 930 sharing files through iTunes, 893 should, delegate method names with, 256 signature of a function, 22 signature of a method, 53, 59 significant location monitoring, 871 Simulator, 190 Debug menu, 191, 411, 414, 592, 865 single tap vs double tap, 471, 478 Single View Application, 336, 498, 514 singleton, 78 Size inspector, 108, 139 size of a graphics context, 378 size of a label, 673 size of a popover, 651 sizeof operator, 24 slider, 722 slowing animation, 414 small caps, 693 Smalltalk, 43 SMS messages, 845 snapshots, 198 snippets, 176 sound (see audio) source code for Cocoa, 73 speed, 870 split views, 649, 664–669 split views, alternatives to, 666 split views, keeping both views when rotated, 666 SQLite, 911 stack, 39, 47 stack, navigation bar, 541, 734 stack, navigation controller, 541 standard C library, 27 standard C library, forgetting about, 28 state of a button, 728 state of a control, 717 state of a graphics context, 372 state, maintenance of, 38 state, saving, 269, 892 static analyzer, 189, 283 static tables, 628 static typing, 58 static variables, 30 status bar, 342, 509 stepper, 718 storyboard files, xxiv, 123, 517, 557 (see also nib files) main storyboard, 123, 127, 518 storyboard, main, and main window instance, 336, 518 storyboard, main, and root view controller, 518 storyboard, table view designed statically in, 628 storyboard-instantiated view controller, 517, 558 storyboard-loaded cells, 609 storyboards, 517–519, 557–562 Index | 977 www.it-ebooks.info relationships, 557 scene, 518, 557 segue, 518, 557 stretchable images superseded by resizable images, 358 stretching a resizable image, 358 string, (see also C string) (see also NSString) strings files, 173 strong, 314 struct pointer (see CFTypeRef) struct properties, setting, 93 structs, structs, logging, 181 structs, wrapping in an object, 233 structure pointer operator, 90 stuttering animation, 410 styled text, 671, 688 subclass, 67 subclass legal where superclass expected, 82 subclassing in Cocoa, 217, 246 subclassing UIApplication, 219, 489 subclassing UIGestureRecognizer, 479 subclassing UIWindow, 336, 489 subclassing view controllers, 497, 537, 544 sublayer, 392 sublayerTransform, 406 Subversion, 197 subview, 135, 335 subviews, animating, 429, 454 subviews, layout of, 346 subviews, removing all, 341 super, 86 superclass, 67 superclass documentation, forgetting, 83, 160, 247 superlayer, 392 superview, 135, 335 suspension of the app, 267, 416, 564, 944 switch, 718 switch statement, 17 switch, customizing color, 718 Symbol navigator, 104, 178 symbol(s) not found, 130 symbol, renaming, 131 symbolic breakpoint, 185 symbols, searching for, 165 syntax checking, 177 synthesize directive, 316 synthesized accessor, 316 synthesized accessor, overriding, 317 synthesized instance variable, 316 system (iOS) versions, xxiii, 169 System Sound Services, 763 T tab bar, 536, 738 tab bar interface, 536 tab bar interface, configuring, 538 tab bar item, 536, 738 images for tab bar items, 538 More item in tab bar, 540, 739 tab bar item, creating, 537 tab bar item, customizing, 739 tab bar, customizing, 739 Tabbed Application, 540 table views, 593–648 (see also cells) cell identifier paired with nib, 607 cells, built-in styles, 597 cells, configuration of, 600 cells, menus in, 646 cells, reusing, 613 data in table view, 611 data in table view, downloading, 920 data in table view, refreshing, 620 editing a table view, 636 grouped table view, 595 height of table view row, 602, 621 index of a table view, 617 multiple cell selection, 623 navigation interface, 625 search results in table view, 630, 662 sections of a table view, 616 sections of a table view, collapsing, 645 selection in a table view, 623 separators in table views, 602 storyboard, table view designed statically in, 628 tabs in Xcode, 110 tap, single vs double, 471, 478 target, 114 target integrity warning, 163 target, action, 259 target, renaming, 131 Targeted Device Family build setting, 169 template (see project template) 978 | Index www.it-ebooks.info ternary operator, 15 text, 671–696 text field in alert view, 748 text fields, 674–685 control events of a text field, 682 delegate of a text field, 681 keyboard, 676–681 menus in a text field, 683 text layers, 401, 690 text views, 685–688 keyboard, 687–688 selection in a text view, 686 text views, self-sizing, 686 texting, 845 there can be only one (movie playing), 788 thread-safety of drawing, 362, 578 threads, 927–946 dealloc and threads, 931 drawing in a background thread, 582 Grand Central Dispatch, 940 interface and threads, 928 locks, 931 main thread, 928 manual threading, 933 NSOperation, 935 shared data, 930 thumb of a slider, 722 TIFF, converting to, 913 tiling, 577 tiling a resizable image, 358 timers, 253 timers and retain cycles, 305 times, 232 toll-free bridged memory management, 311 toll-free bridging, 62 toll-free bridging and ARC, 63, 310 toolbar, 542, 738 search bar in a toolbar, 662, 716 toolbar items, 549, 738 toolbar, customizing, 738 toolbar, hiding and showing, 549, 563 top and bottom reversed, 400, 445 top item, 541 top-level objects, 135 touch phases, 464 touches, 463–494 delivery of touches, 483 responders and touches, 493 restricting touches, 467, 491 touches in a control, 259, 731 touches in a scroll view, 587 touches… methods, 466 TouchXML, 910 track of a slider, 722 transactions, 431 transform, 349, 382, 403 transform, depth, 406 transitions, 424, 428, 445 transitions, animation options extended, 429 transparency, 353, 399 transparency layer, 385 transparent background, 371, 375, 399 transparent pixels, 488 typecasting, typecasting and ARC, 308, 312 typecasting to quiet compiler, 56, 63, 64, 82, 337, 396, 402, 451 U UIAccelerometer, 876 UIActionSheet, 750 UIActivityIndicatorView, 707 UIAlertView, 748 UIApplication shared application instance, 78, 127 subclassing UIApplication, 219, 489 UIBarButtonItem, 544, 735, 738 UIBarItem, 537, 544 UIBezierPath, 376 UIButton, 727 UIControl, 716 (see also controls) UIDatePicker, 720 UIDocument, 899 UIDocumentInteractionController, 896 UIEdgeInsets, 357, 574 UIEvent, 463 UIGestureRecognizer, 473 (see also gesture recognizer) subclassing UIGestureRecognizer, 479 UIGestureRecognizer built-in subclasses, 474 UIImage, 355, 360 (see also images) UIImage animation, 418 UIImagePickerController, 809 UIImageView, 355 UIImageView animation, 417 UIKit framework, 129 Index | 979 www.it-ebooks.info UILabel, 219, 599, 672–673 (see also labels) UILocalizedIndexedCollation, 618 UILocalNotification, 756 UIMenuController, 684, 952 UIMenuItem, 684, 952 UINavigationBar, 540, 734 UINavigationController, 541 UINavigationItem, 541, 546, 734 UIPageControl, 719 UIPageViewController, 551 UIPickerView, 257, 711 UIPopoverController, 651 (see also popovers) UIPopoverController, reference to, 656, 663 UIPopoverControllers, distinguishing, 659 UIProgressView, 708 UIResponder, 263 UIScrollView, 569 (see also scroll views) UISearchBar, 713 UISearchDisplayController, 630, 662 UISegmentedControl, 725 UISlider, 722 thumb of a slider, 722 track of a slider, 722 UISplitViewController, 664 (see also split views) UIStepper, 718 UIStoryboardPopoverSegue, 660 UIStoryboardSegue, 557 UISwitch, 718 UITabBar, 536, 738 UITabBarController, 536 UITabBarItem, 536, 738 UITableView, 593 (see also table views) UITableViewCell, 593 (see also cells) UITableViewController, 595 UITableViewController, forgetting to specify nib name, 513 UITextField, 674 (see also text fields) UITextView, 685 (see also text views) UIToolbar, 542, 738 UITouch, 463, 466 (see also touches) UIVideoEditorController, 789 UIView, 218, 335 (see also views) UIViewController, 497 (see also view controllers) UIWebView, 697 (see also web views) UIWindow, 335, 336 (see also window) subclassing UIWindow, 489 unarchiving data, 890 undeclared symbol, 129 underlying layer, 390 underlying layer, animating, 430, 434 undo alert, button titles in, 951 Undo and Redo, 947–955 Undo by shaking, 875, 951 Unicode characters, uninitialized instance reference, 45, 181 unique an array, 237 unit testing, 188 universal app, 124, 169 unrecognized selector, 55, 57 unregistering for a notification, 251, 302 unsafe references, 301 uppercase class names, 44 URL, 698 base URL, 700 user address book, 823 user calendar, 831 user defaults, 891 user denied access, 821 user interaction, allowing, 425 user interaction, during view animation, 425 user interaction, preventing, 416, 467 user library, music, 797 user library, photo, 809 Utilities pane, 108 Utility Application, 227, 257 V variable is not assignable, 65 variables, const variables, 29 declaring a variable, 6, 44 external (global) variables, 307 initialization of variables, 6, 44 instance references, 43 instance variables, 37, 89 980 | Index www.it-ebooks.info lowercase variable names, static variables, 30 variables list, 106, 186 version control, 196 version string, 211 versions of iOS, xxiii, 169 versions of Xcode, xxiii video, 781–796 video playback controls, 783 video, recording, 812 video, trimming, 789 view animation, 419 view controller for address book, 826 view controller for calendar, 838 view controller for mail, 845 view controller for music library, 806 view controller for photo library, 809 view controller for playing video or audio, 788 view controller for taking pictures, 812 view controller for trimming video, 789 view controller hierarchy, 500 view controller's view, creating, 507–519 view controllers, 497–568 child view controller, 498 contained view controllers, 498 delegate of a view controller, 562 memory management of view controllers, 565 modal view controller, 498, 526 navigation bar, hiding and showing, 551 navigation item, 546 nib name matching view controller, 512 nib-instantiated view controller, 515 nib-loaded view of view controller, 511 parent view controller, 498 parent view controller, custom, 554 presented view controller, 499, 526 root view controller, 498, 500 rotating interface, 534, 537, 544 storyboard-instantiated view controller, 517, 558 subclassing view controllers, 497, 537, 544 toolbar items, 549 toolbar, hiding and showing, 549, 563 view controllers (dis)appearing, reason for, 563 view controllers, creating, 504–519 view controllers, lifetime events of, 562 view controllers, retaining, 504 view controller’s view, loading of, 515 view controller’s view, placement in view hierarchy, 500, 506, 554 view controller’s view, populating, 510 view controller’s view, unloading of, 565 view coordinates, 344 view for map, 847 view for playing video or audio, 782 view hierarchy, 339 viewDidLoad, 513 viewport, 703 views, 134, 335–494 animating a view, 419 autoresizing, 347 black background, 371, 375 bounds, 343 content mode, 386 dragging a view, 468, 476 drawing a view, 370 frame, 341 gesture recognizers, views, and touch delivery, 490 hidden, 353 hit-testing views, 484 layering order of views, 340 layout of subviews, 346 layout of subviews during animation, 428 misaligned images, 192, 346 modal views, 526 opaque, 354, 371 overlapping views, 339 position of a subview, 341 root view, 336, 498 transform, 349 transparency, 353 transparent background, 371, 375 underlying layer, 390 view controller’s view, loading of, 515 view controller’s view, unloading of, 565 visibility of one instance to another, 321 void, 21, 50 W warning directive, 29 warnings applications are expected to have a root view controller, 338, 498 class does not implement protocol, 225 class may not respond to, 54 Index | 981 www.it-ebooks.info incomplete implementation, 225 method not found, 54 passing to parameter of incompatible type, 225 presenting action sheet clipped by its superview, 751 typecasting to quiet compiler, 56 weak references, 300 weak-linking, 172 weak–strong dance, 304 web views, 671, 697–705 WebKit, 697 while loop, 16 width and height reversed, 524 window, main, 336 (see also main window) windows, secondary, in Xcode, 110 X Xcode, 99–213 archives, 205, 211 assistant pane, 109, 179 Attributes inspector, 108, 138 autocompletion, 175 build configurations, 117 build phases, 114 build settings, 115 canvas (nib editor), 136 cleaning, 189 Code Snippet library, 108, 176 configurations, 117 connections, 143 action connections, 151 outlet connections, 143 Connections inspector, 108, 146, 148, 152 console, 106 Debug pane, 106, 185 debugging, 180 destinations, 119 dock (nib editor), 135 documentation, 157 editing your code, 174 editor, 109 executable, 126 File inspector, 108 File Template library, 108 File’s Owner proxy object, 141 First Responder proxy object, 265 Fix-it, 177 groups, 103 Identity inspector, 108, 138 Info.plist, 121, 122, 210 jump bar, 109, 136, 178, 186 keyboard shortcuts in Xcode, 103 labels in nib editor, 136 Media library, 108, 140 navigating your code, 177 Navigator pane, 103 navigators Breakpoint navigator, 107 Debug navigator, 105, 185 Issue navigator, 104 Log navigator, 107 Project navigator, 103, 178 Search navigator, 104 Symbol navigator, 104, 178 Object library, 108, 137 outlet collections, 150 outlets, 143 precompiled header, 128 profiling, 198 project file, 111 project templates, 100 Empty Application, 338 main window, 336 Master–Detail Application, 625, 665 Single View Application, 336, 498, 514 Tabbed Application, 540 Utility Application, 227, 257 project window, 102 Quick Help, 108, 164 resources, 124 running on a device, 192 schemes, 118 searching your code, 179 Size inspector, 108, 139 static analyzer, 189, 283 target, 114 unit testing, 188 Utilities pane, 108 variables list, 106, 186 version control, 196 versions of Xcode, xxiii xib file extension, 133 XML, 904 Y YES, 20 982 | Index www.it-ebooks.info Z zombies, 283 zooming, 579 zooming with CATiledLayer, 582 Index | 983 www.it-ebooks.info www.it-ebooks.info About the Author Matt Neuburg has a PhD in Classics and has taught at many universities and colleges He has been programming computers since 1968 He has written applications for Mac OS X and iOS, is a former editor of MacTech Magazine, and is a long-standing contributing editor for TidBITS His previous O'Reilly books are Frontier: The Definitive Guide, REALbasic: The Definitive Guide, and AppleScript: The Definitive Guide He makes a living writing books, articles, and software documentation, as well as by programming, consulting, and training Colophon The animal on the cover of Programming iOS is a kingbird, one of the 13 species of North American songbirds making up the genus Tyrannus A group of kingbirds is called a “coronation,” a “court,” or a “tyranny.” Kingbirds eat insects, which they often catch in flight, swooping from a perch to grab the insect midair They may also supplement their diets with berries and fruits They have long, pointed wings, and males perform elaborate aerial courtship displays Both the genus name (meaning “tyrant” or “despot”) and the common name (“kingbird”) refer to these birds’ aggressive defense of their territories, breeding areas, and mates They have been documented attacking red-tailed hawks (which are more than twenty times their size), knocking bluejays out of trees, and driving away crows and ravens (For its habit of standing up to much larger birds, the gray kingbird has been adopted as a Puerto Rican nationalist symbol.) “Kingbird” most often refers to the Eastern kingbird (T tyrannus), an average-size kingbird (7.5–9 inches long, wingspan 13–15 inches) found all across North America This common and widespread bird has a dark head and back, with a white throat, chest, and belly Its red crown patch is rarely seen Its high-pitched, buzzing, stuttering sounds have been described as resembling “sparks jumping between wires” or an electric fence The cover image is from Cassell’s Natural History The cover font is Adobe ITC Garamond The text font is Linotype Birka; the heading font is Adobe Myriad Condensed; and the code font is LucasFont’s TheSansMonoCondensed www.it-ebooks.info www.it-ebooks.info ... www.it-ebooks.info 50 0 50 4 50 7 50 9 51 1 51 4 51 7 51 9 52 1 52 3 52 6 53 1 53 2 53 4 53 6 53 7 53 8 54 0 54 4 54 6 54 9 54 9 55 1 55 4 55 7 56 2 56 4 20 Scroll Views 56 9 Creating... Scroll View Touches Scroll View Performance 57 0 57 3 57 6 57 7 57 9 58 1 58 1 58 4 58 6 59 1 21 Table Views 59 3 Table View Cells Built-In Cell Styles... Parameter Lists Unrecognized Selectors Typecasting and the id Type Messages as Data Type C Functions CFTypeRefs Blocks 47 49 49 50 51 52 53 53 54 56 59 60 62 63 Objective-C Classes
- Xem thêm -

Xem thêm: 684 programming iOS 5, 2nd edition covers iOS 5 and xcode 4 3 , 684 programming iOS 5, 2nd edition covers iOS 5 and xcode 4 3 , Chapter 3. Objective-C Objects and Messages, Chapter 6. Anatomy of an Xcode Project, Chapter 9. Life Cycle of a Project, Chapter 12. Accessors and Memory Management, Chapter 22. Popovers and Split Views, Chapter 25. Controls and Other Views, Chapter 30. Photo Library and Image Capture

Mục lục

Xem thêm