Basic interaction between IOS-MVC model and Processing

Source: Internet
Author: User

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
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.