9

Modern Objective-C und Cocoa - mitpmedia.mitp.de/vmi-buch/texte/inhaltsverzeichnis/...Inhaltsverzeichnis 9 13.5 Programmende und NSRunAlertPanel . . . . . . . . . . . . . . . .

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

  • 5

    Inhaltsverzeichnis

    Danksagung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    Einleitung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

    Teil I Grundlagen von Objective-C 19

    1 Grundlagen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211.1 Das Cocoa Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221.2 Die typische Objective-C-Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231.3 Kontrollstrukturen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251.4 Namenskonventionen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271.5 Kommentare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291.6 Stilmittel in den Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    2 Durchstarten mit Xcode 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.1 Die Installation von Xcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.2 Das erste Projekt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352.3 Das Workspace-Fenster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382.4 Der Project Editor und seine Targets . . . . . . . . . . . . . . . . . . . . . . . . . . 402.5 Der Navigator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412.6 Der Texteditor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422.7 Die Debugger-Ansicht . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442.8 Die Einstellungen von Xcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462.9 Die main-Methode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492.10 Die Schnellhilfe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512.11 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

    3 NSLog, Variablen und Format Specifier . . . . . . . . . . . . . . . . . . . . . . . 533.1 Programmieren mit Code Sense . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533.2 Zahlen formatieren mit Format Specifier . . . . . . . . . . . . . . . . . . . . . . 563.3 Zeichenketten mit NSString . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603.4 Enum – Enumerated Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653.5 Vergleichen von Zeichenketten . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

    © des Titels »Modern Objective-C und Cocoa« (ISBN 978-3-8266-9701-2) 2014 by Verlagsgruppe Hüthig Jehle Rehm GmbH, Heidelberg.

    Nähere Informationen unter: http://www.mitp.de/9701

    http://www.mitp.de/9701

  • Inhaltsverzeichnis

    6

    3.6 Zeichenketten sortieren. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703.7 Textteilbereiche mit NSRange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723.8 NSMutableString . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763.9 NSMutableString und Zeiger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 813.10 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

    4 Klassen und Objekte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854.1 Header und Implementierung einer Objective-C-Klasse . . . . . . . . . . 854.2 Die Erben von NSObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 874.3 Hinzufügen einer neuen Objective-C-Klasse . . . . . . . . . . . . . . . . . . . 884.4 Instanzvariablen und Accessor-Methoden . . . . . . . . . . . . . . . . . . . . . . 934.5 #import für die neue Klasse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984.6 Objekte erzeugen mit init, alloc oder new . . . . . . . . . . . . . . . . . . . . . . 994.7 Methoden im Einsatz. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1024.8 Methodenaufrufe mit self . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1034.9 Key Value Coding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1054.10 Die Klassenbeschreibung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1084.11 Polymorphie, Selektoren und Enten . . . . . . . . . . . . . . . . . . . . . . . . . . 1104.12 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

    5 Speicherverwaltung und Objektreferenzen . . . . . . . . . . . . . . . . . . . . . 1135.1 Der Referenzzähler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1135.2 Die Klasse Person . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1155.3 Objekte kopieren in Accessor-Methoden . . . . . . . . . . . . . . . . . . . . . . . 1185.4 Individuelle Initialisierungen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1205.5 Klassenmethoden. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1225.6 Besitzer sind verantwortlich . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1245.7 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

    6 Objective-C wird modern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1276.1 Properties – Die Eigenschaften einer Klasse . . . . . . . . . . . . . . . . . . . . 1276.2 Eigenschaften statt Accessor-Methoden. . . . . . . . . . . . . . . . . . . . . . . . 1286.3 Referenzen mit weak und strong . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1306.4 Eigenschaften auf Methoden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1316.5 Respekt vor dem Unteilbaren . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1336.6 Eigenschaften mit anderen Variablen verbinden . . . . . . . . . . . . . . . . 1346.7 Benutzerdefinierte Bezeichner für Eigenschaften . . . . . . . . . . . . . . . 1366.8 Die Punktnotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1376.9 Die Modern-Objective-C-Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1386.10 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

    © des Titels »Modern Objective-C und Cocoa« (ISBN 978-3-8266-9701-2) 2014 by Verlagsgruppe Hüthig Jehle Rehm GmbH, Heidelberg.

    Nähere Informationen unter: http://www.mitp.de/9701

    http://www.mitp.de/9701

  • Inhaltsverzeichnis

    7

    7 Der Debugger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1417.1 Haltepunkte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1427.2 Debugging mit Einzelschritten. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1447.3 Editieren im Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1467.4 Step In und Step Out. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1477.5 Debug Navigator und Aufrufstapel . . . . . . . . . . . . . . . . . . . . . . . . . . . 1507.6 Breakpoint Navigator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1527.7 Haltepunkt mit Bedingungen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1527.8 Benachrichtigung durch Haltepunkte . . . . . . . . . . . . . . . . . . . . . . . . . 1547.9 Makros für die Fehlersuche . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1557.10 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

    8 Robuste Anwendungen und automatisierte Tests . . . . . . . . . . . . . . . 1598.1 Methoden mit Parametern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1598.2 Kommentare für Methoden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1628.3 Assertions – Die Behauptungen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1658.4 Kompilieren als Debug oder Release . . . . . . . . . . . . . . . . . . . . . . . . . . 1668.5 Automatisiertes Testen mit Xcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1708.6 Überprüfung der Kontrollen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1758.7 Umstellungen auf Modern Objective-C . . . . . . . . . . . . . . . . . . . . . . . . 1778.8 Der Umgang mit unbenutzten Variablen . . . . . . . . . . . . . . . . . . . . . . 1808.9 Ein paar Fragen.... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

    9 Vererbung, Kategorien und Protokolle . . . . . . . . . . . . . . . . . . . . . . . . 1859.1 Das Erbe der Klasse Person . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1869.2 Erweiterungen der abgeleiteten Klasse . . . . . . . . . . . . . . . . . . . . . . . . 1889.3 Methoden überschreiben . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1919.4 Die Initialisierung von abgeleiteten Klassen . . . . . . . . . . . . . . . . . . . . 1949.5 Protokolle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1969.6 BOOL – Ein besonderer Datentyp . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1999.7 Das NSCoding Protokoll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2009.8 Serialisierung leicht gemacht . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2049.9 Die Abhängigkeit von Zeichenketten. . . . . . . . . . . . . . . . . . . . . . . . . . 2069.10 Kategorien . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2089.11 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

    10 Array & Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21510.1 Personenliste – Ein Array mit Personen . . . . . . . . . . . . . . . . . . . . . . . 21610.2 NSMutableArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21810.3 Schnell durchs Array mit Fast Enumeration . . . . . . . . . . . . . . . . . . . . 21910.4 Vielfältige Manipulationen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222

    © des Titels »Modern Objective-C und Cocoa« (ISBN 978-3-8266-9701-2) 2014 by Verlagsgruppe Hüthig Jehle Rehm GmbH, Heidelberg.

    Nähere Informationen unter: http://www.mitp.de/9701

    http://www.mitp.de/9701

  • Inhaltsverzeichnis

    8

    10.5 Arrays sortieren . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22410.6 Ein Array mit NSNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22810.7 Dictionaries – Die schnellen Wörterbücher. . . . . . . . . . . . . . . . . . . . . 23010.8 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234

    Teil II Cocoa-Anwendungen 235

    11 Hello Cocoa World – eine Cocoa-Anwendung . . . . . . . . . . . . . . . . . . 23711.1 MVC: Model – View – Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23711.2 Nib-Dateien und der Interface Builder. . . . . . . . . . . . . . . . . . . . . . . . . 23911.3 Projektvorlage: Cocoa Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24011.4 Dock und Outline View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24311.5 Inspector und Bibliothek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24411.6 Arbeiten mit dem Interface Builder . . . . . . . . . . . . . . . . . . . . . . . . . . . 24811.7 Der Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25111.8 Action und Outlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25211.9 Zurück zum Interface Builder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25611.10 Das war es jetzt schon? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26011.11 awakeFromNib – Die Oberfläche wacht auf . . . . . . . . . . . . . . . . . . . . 26111.12 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262

    12 Datenein- und -ausgabe auf der grafischen Oberfläche . . . . . . . . . . . 26312.1 Die Klasse AppDelegate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26312.2 Eine grafische Oberfläche entsteht . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26512.3 Der Size Inspector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26812.4 Auftritt für den Assistenten . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27012.5 Ein GeometryCalculator für den Controller. . . . . . . . . . . . . . . . . . . . . 27512.6 Lazy Instantiation – Die Instanz kommt später . . . . . . . . . . . . . . . . . 27612.7 Es darf gerechnet werden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27712.8 Zahlen formatieren mit dem NSNumberFormatter . . . . . . . . . . . . . . 27912.9 Umgestalten durch Refactoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28212.10 EVA und MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28412.11 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285

    13 Hinter den Kulissen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28713.1 Was verbirgt sich hinter IBAction und IBOutlet? . . . . . . . . . . . . . . . . 28713.2 First Responder und Tab-Reihenfolge . . . . . . . . . . . . . . . . . . . . . . . . . 28813.3 Icons für die Anwendung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29213.4 Das About-Fenster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294

    © des Titels »Modern Objective-C und Cocoa« (ISBN 978-3-8266-9701-2) 2014 by Verlagsgruppe Hüthig Jehle Rehm GmbH, Heidelberg.

    Nähere Informationen unter: http://www.mitp.de/9701

    http://www.mitp.de/9701

  • Inhaltsverzeichnis

    9

    13.5 Programmende und NSRunAlertPanel . . . . . . . . . . . . . . . . . . . . . . . . 29613.6 Auf den Spuren der Anwendung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29913.7 Ein Blick ins Bundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30113.8 Aufgeräumt wird zum Schluss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30213.9 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303

    14 Sprachausgabe und Delegation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30514.1 SpeakEasy – Eine Anwendung lernt sprechen . . . . . . . . . . . . . . . . . . 30514.2 Sprache ist asynchron . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30914.3 Delegation – Meine Nachrichten an dich . . . . . . . . . . . . . . . . . . . . . . 30914.4 Sprachausgabe: Start und Stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31314.5 Viele Stimmen zur Auswahl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31814.6 Voice Identifier – Eine Stimme wird identifiziert. . . . . . . . . . . . . . . . 32014.7 Der NSPopUpButton in Aktion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32314.8 Ein Delegate für die Anwendung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32414.9 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327

    15 Hallo Taxi! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32915.1 Die Klasse TaxiFareCalculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32915.2 Die Methode calculateFare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33115.3 Schieberegler – NSSlider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33215.4 Nachricht mit Absender . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33515.5 Zu große Genauigkeit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33615.6 Wer ist der Absender? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33815.7 Kontrollkästchen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34015.8 Eine Action für viele Steuerelemente. . . . . . . . . . . . . . . . . . . . . . . . . . 34115.9 Schriftarten und formatierte Zahlen . . . . . . . . . . . . . . . . . . . . . . . . . . 34315.10 Endspurt zum fertigen Programm. . . . . . . . . . . . . . . . . . . . . . . . . . . . 34515.11 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350

    16 Benutzereinstellungen und noch mehr Delegation . . . . . . . . . . . . . . 35116.1 Am Anfang war das Protokoll. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35116.2 Kleine Änderungen erforderlich. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35416.3 Umsetzung eines eigenen Delegate . . . . . . . . . . . . . . . . . . . . . . . . . . . 35616.4 Zirkelverweise und schwache Verbindungen . . . . . . . . . . . . . . . . . . . 35816.5 Optionale Methoden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35916.6 Benutzereinstellungen – NSUserDefaults . . . . . . . . . . . . . . . . . . . . . 36216.7 Speichern der Einstellungen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36416.8 Property Liste und plist Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36516.9 Das Laden der Einstellungen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368

    © des Titels »Modern Objective-C und Cocoa« (ISBN 978-3-8266-9701-2) 2014 by Verlagsgruppe Hüthig Jehle Rehm GmbH, Heidelberg.

    Nähere Informationen unter: http://www.mitp.de/9701

    http://www.mitp.de/9701

  • Inhaltsverzeichnis

    10

    16.10 Fehlt da nicht noch etwas? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37216.11 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375

    17 Datenquellen und Tabellen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37717.1 Ein Controller für eine Tabelle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37717.2 Daten für den Tabellen-Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38017.3 Tabellen und Controller im Interface Builder . . . . . . . . . . . . . . . . . . 38217.4 Spalten für die Tabelle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38517.5 Die Datenquelle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38817.6 Erste Schritte mit Autolayout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39217.7 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394

    18 Sortierte Tabellen mit Drag und Drop . . . . . . . . . . . . . . . . . . . . . . . . . 39518.1 Es darf sortiert werden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39618.2 Geht es auch andersherum? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39918.3 Und wo sind die Pfeile? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40218.4 Drag und Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40518.5 Bitte hier kräftig ziehen! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40818.6 Sie dürfen ablegen! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40918.7 Mehr Ordnung für die Klasse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41318.8 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415

    Teil III iOS-Anwendungen für iPhone & Co 417

    19 iOS und Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41919.1 Action und Outlet auch für iOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42319.2 Der View im Interface Builder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42519.3 viewDidLoad – Der View wurde geladen . . . . . . . . . . . . . . . . . . . . . . . 42819.4 Ein Icon für die App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42919.5 Das Startbild . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43119.6 Von Xcode zum Gerät – Der Organizer . . . . . . . . . . . . . . . . . . . . . . . . 43219.7 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434

    20 Texteingaben und virtuelle Tastaturen. . . . . . . . . . . . . . . . . . . . . . . . . 43520.1 Textfelder und Tastaturtypen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43520.2 Eingaben beenden: Keine einfache Aufgabe . . . . . . . . . . . . . . . . . . . 43820.3 Der Nächste bitte: Eine Eingabekette . . . . . . . . . . . . . . . . . . . . . . . . . . 44120.4 Meldungen mit UIAlertView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44420.5 Wollen Sie wirklich löschen? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447

    © des Titels »Modern Objective-C und Cocoa« (ISBN 978-3-8266-9701-2) 2014 by Verlagsgruppe Hüthig Jehle Rehm GmbH, Heidelberg.

    Nähere Informationen unter: http://www.mitp.de/9701

    http://www.mitp.de/9701

  • Inhaltsverzeichnis

    11

    20.6 Alles dreht sich – oder auch nicht! . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45120.7 Vom UIView zum UIControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45520.8 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457

    21 Storyboards – Mit dem Drehbuch durch die App . . . . . . . . . . . . . . . . 45921.1 Ein Storyboard mit zwei Ansichten . . . . . . . . . . . . . . . . . . . . . . . . . . . 45921.2 Segue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46121.3 Der Lebenszyklus einer Szene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46521.4 Storyboard mit Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46621.5 Eine Szene für die Farben. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47121.6 Ein Segue für den Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47321.7 Methoden für den Übergang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47721.8 Zurück per Delegate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47921.9 Vorsicht mit Referenzen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48321.10 Eine weitere Szene. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48421.11 Delegate und Protokoll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48921.12 Eltern-Kind-Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49221.13 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493

    22 CountryDB – Eine Länderdatenbank . . . . . . . . . . . . . . . . . . . . . . . . . . 49522.1 Eine leere Anwendung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49622.2 Die Klasse Country . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50122.3 Ein Array mit Länderinformationen . . . . . . . . . . . . . . . . . . . . . . . . . . 50322.4 Ein Controller für die Tabellenansicht. . . . . . . . . . . . . . . . . . . . . . . . . 50422.5 Der View für die Detailansicht . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50922.6 Aus dem Objekt auf den View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51122.7 Anzeigen der Detailansicht . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51422.8 Ein Titel für den View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51722.9 Farbe für die Tabelle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51922.10 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522

    23 Tableisten-Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52323.1 Tableiste und Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52423.2 Gibt es hier keinen Delegate? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52823.3 Konfiguration der Schaltflächen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53123.4 Ein Farbmischer mit Schiebereglern . . . . . . . . . . . . . . . . . . . . . . . . . . 53523.5 Farben mit UIColor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53823.6 Und jetzt als Hex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54123.7 Eine Kategorie für UIColor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54423.8 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548

    © des Titels »Modern Objective-C und Cocoa« (ISBN 978-3-8266-9701-2) 2014 by Verlagsgruppe Hüthig Jehle Rehm GmbH, Heidelberg.

    Nähere Informationen unter: http://www.mitp.de/9701

    http://www.mitp.de/9701

  • Inhaltsverzeichnis

    12

    24 Picker und Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54924.1 Daten für den Picker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55224.2 Wohin geht die Reise? Anzeige der Auswahl . . . . . . . . . . . . . . . . . . . 55624.3 Das Steuerelement UISegmentedControl . . . . . . . . . . . . . . . . . . . . . . 55924.4 Ein View bekennt Farbe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56124.5 Startvorbereitungen mit Autolayout . . . . . . . . . . . . . . . . . . . . . . . . . . . 56424.6 Es bewegt sich: Eine Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56824.7 Alles so schön bunt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57024.8 Ein paar Fragen ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571

    A Fragen und Antworten . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573

    B Glossar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583

    Stichwortverzeichnis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589

    © des Titels »Modern Objective-C und Cocoa« (ISBN 978-3-8266-9701-2) 2014 by Verlagsgruppe Hüthig Jehle Rehm GmbH, Heidelberg.

    Nähere Informationen unter: http://www.mitp.de/9701

    http://www.mitp.de/9701