Mar 7, 2012 - +: class methods, sent to class, not object (e.g. alloc). Page 5. iOS: XCode and Interface. Builder. Tommy
iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode
iOS: XCode and Interface Builder
Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
Tommy MacWilliam
[email protected]
March 7, 2012
Today iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder
I
Objective-C Review
I
XCode
I
Outlets and Actions
Outlets and Actions
I
Delegates and Protocols
Delegates and Protocols
I
Tic-Tac-Toe
Tic-Tac-Toe
Classes iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review
I
@interface: .h files
XCode
I
Interface Builder
I
Outlets and Actions Delegates and Protocols Tic-Tac-Toe
I
declare class methods and properties @class Something to use other classes
@implementation: .m files I I
define class methods and synthesize properties #import “Something.h” to use other classes
Classes iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
I
-: instance methods, sent to objects (e.g. init)
I
+: class methods, sent to class, not object (e.g. alloc)
Properties iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode
I
I
Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
@property (nonatomic, assign) int foo;
I
declare new property, specify how values are assigned
@synthesize foo = _foo; I
generate getters/setters for property
Message Passing iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder
I
- (id)init
I I
- (id)initWithName:(NSString*)name - (id)initWithName:(NSString*)name age:(int)age
I
[object initWithName:@”name”];
Outlets and Actions Delegates and Protocols Tic-Tac-Toe
GDB iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder
I
create breakpoint by clicking on line number
I
next: continue line-by-line
I
step: go into a called function
Outlets and Actions
I
continue: resume execution until next breakpoint
Delegates and Protocols
I
print or mouse over variable to see value
Tic-Tac-Toe
Objective-C and GDB iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
I
GDB
Interface Builder iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder
I
File Inspector: nib options
I
Quick Help: view documentation for the selected UIView
I
Identity Inspector: modify object properties
Outlets and Actions
I
Attributes Inspector: customize the selected UIView
Delegates and Protocols
I
Size Inspector: change placement/size of UIView
Tic-Tac-Toe
I
Connections Inspector: manage outlets/actions
Interface Builder iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review
I
File’s Owner: object that loads nib
I
First Responder: UIView currently in focus and responding to input
Outlets and Actions
I
App Delegate: responsible for loading, resuming, etc.
Delegates and Protocols
I
Window: container for UIView
XCode Interface Builder
Tic-Tac-Toe
Outlets iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
I
IBOutlet tells XCode the object represents something in IB I I
NOT the type of the object, just a flag @property (nonatomic, strong) IBOutlet UIButton* button;
Using Outlets iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode
I
define UIView properties in @interface
Interface Builder
I
synthesize UIView properties in @implementation
Outlets and Actions
I
connect Objects in Interface Builder
Delegates and Protocols Tic-Tac-Toe
Connecting Outlets iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review
I
select placeholder where property is defined (File’s Owner or App Delegate)
I
Ctrl-Click and drag to UIView
I
select name of outlet
I
???
I
profit!
XCode Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
Actions iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
I
IBAction tells XCode the method is used by something in IB I
equivalent to the void type, so all methods are void
Connecting Actions iOS: XCode and Interface Builder Tommy MacWilliam
I
select UIView to fire callback for, open Connections Inspector
I
Ctrl-Click callback, drag to placeholder where method is defined (File’s Owner or App Delegate)
Outlets and Actions
I
select name of method
Delegates and Protocols
I
???
Tic-Tac-Toe
I
profit!
Objective-C Review XCode Interface Builder
Outlets and Actions iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
I
TextFieldExample
Delegate iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode
I
define object to handle actions
Interface Builder
I
delegate object implements a protocol
Outlets and Actions Delegates and Protocols Tic-Tac-Toe
I
guarantees definitions for methods exist
Protocol iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
@protocol SomeProtocol - (void)something - (int)calculateSomething:(int) @end
UITextFieldDelegate iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review
I
textFieldShouldReturn: “done” button pressed
I
textFieldShouldBeginEditing: user about to edit text
I
textFieldShouldEndEditing: text field about to lose focus
XCode Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
Using Protocols and Delegates iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
I
BetterTextFieldExample
I
UtilityApp
Putting it All Together iOS: XCode and Interface Builder Tommy MacWilliam Objective-C Review XCode Interface Builder Outlets and Actions Delegates and Protocols Tic-Tac-Toe
I
TicTacToe I I
our first of many award-winning apps follow along!