2011年12月28日 星期三

Interface builder basic

.xib file (nib file)

File's owner: denotes the object that load the xib file. I.e. instantiate all objects described in the xib file

First responder: object that user currently interacting with

View

Outlet : connect interface object to class variable
Action: class method that will be called when an event takes place

To connect outlet: from file's owner to view
Use ctrl-drag n drop file's owner icon to screen image to connect interface item to outlet.

To connect action: from view's connection inspector to File's owner
Open object's connection inspector, click n drag the circle of event to File's owner icon.
P.s. can connect to another object instead of file's owner too. Ex. WebView object's goBackward action.

If wanna use a custom class, say myGenericButton instead of UIButton,
Select button object and open identity inspector, change class identifier to ur desired custom class.

Outlet and action are defineded in ViewController.h
For example:
IBOutlet UILabel *myLabel;
-(IBAction)doCalculation:(id)sender;


How to tell which xib to use in ur app?
For project created by using view-based project template:
By default, In info.plist> main nib file base name = MainWindow
In MainWindow.xib, open attribute inspector on the viewController, nib name property tells which xib to use. I.e. {appName}ViewController.xib

ViewDidLoad method is called when view is instantiated from xib file. If wanna change button image, implement here.

To hide keyboard of a text field, use
[myTextField resignFirstResponder]
Usually implement in DidEnd on Exit event of the field.
Or use an invisible button with action connect to hide all keyboard, such that whenever other part of the screen is touched, will hide the keyboard.

Apple sample project: UICatalog . Like kitchensink

沒有留言:

張貼留言