1. MVC (Model-View-Controller). Cocoa Touch designers use the MVC pattern as the guiding principle and use it to split the logic method of GUI (graphical interface) application code.
2. Moudle model: class for storing and processing application data (usually designed with some ObjC classes)
View: A part of window, control, and other elements that interact with users.
Controller: binds models and views to determine how to process user input application logic (typically composed of classes created by developers and application-specific classes)
3. outlet output port: the controller can define special variables to consume the variables in nib and declare the variables as output ports.
For example, define an output port of an existing nib Button:
UIButton * button;
Declared attributes:
@ Property (nonatomic, assign) IBOutlet UIButton * button
IBOutlet can also be written in the definition: IBOutlet UIButton * button; you can leave it empty when declaring an attribute.
4. Operation: The operation declared by IBAction is triggered by the control.
Operation Declaration:-(IBAction) doSomething :( id) sender;
The returned value must be IBAction, which is the same as void.
The parameter is optional. Generally, the id-type sender indicates the control that triggers the operation, which can be referenced inside the operation.
5. Dynamic Button generation and event binding example: Written In The ViewController. m file
Double x = 10; double y = 20;
Double width = 100; double height = 30;
UIButton * btn = [UIButtonbuttonWithType: UIButtonTypeRoundedRect];
Btn. frame = CGRectMack (x, y, width, height );
[Self. view addSubview: btn]; // self is the controller; self. view is the basic view of the program.
// Bind a click event to the button
[Btn addTarget: selfaction: @ selector (ClickMe :) forControlEvents: UIControlEventTouchUpInSide]; // ClickMe: Customize the click button for the user to respond to message events
// Define a ClickMe Click Event: Only one pop-up window is available.
-(IBAction) ClickMe :( id) sender
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Hello" message: @ "you clicked on me !" Delegate: nilcancleButtonTitle: @ "OK" otherButtonTitles: @ "Cancle", nil];
[Alertshow];
[Alertrelease]; // note that the memory must be released to prevent memory leakage
}