IOS basics 07 Action and output port, iosaction

Source: Internet
Author: User

IOS basics 07 Action and output port, iosaction

 

IOS basics 07 Action and output ports

 

Directory:

1. Preface and case description

2. What is action?

3. What is an output port?

4. Practice

5. End

 

 

1. Preface and case description

In the previous article, we learned the labels and buttons. Next we will use a project case with the user interaction function to further practice the use of these two controls, as well as the control of the action and output ports.

 

This case is based on the interface design and functional concept process of the previous article.

1 private void OnClick (object sender, EventArgs e) {2 //... 3}

 

However, in iOS, the return value type of the Action Code is IBAction. The sample code is as follows:

1 @IBAction func onClick(sender: AnyObject) {2     // ...3 }

 

The return type of this method is IBAction, indicating that this method is an action.

Same as the Action Method in. NET WinForm: sender is a parameter and is an event source, indicating the control object that emits the current event. It can also be omitted as follows:

1 @IBAction func onClick() {2     // ...3 }

 

 

 

3. What is an output port?

Note:

The "output port" is a wonderful name. Some friends may not understand it. I will give two examples from the. NET and Android aspects (I won't know anything else ..).

Everyone can understand the best. If you don't understand it, you don't have to go into these two examples. Just look at iOS in a twinkling of an eye.

 

On the. NET WinForm design interface, drag and drop a control. VS will automatically generate the Response Control creation code in the post code of the current form (xxx. Designer. cs.

In this way, you can use this. Control name in the front-end code file to access the control variables in the back-end code to operate the controls on the form.

 

In Android, after we place the control on the design interface, if you need to access the control in the code file, for example:

1 Button btn = (Button)findViewByid(R.id.btnXXX);

In this way, you can use the object btn in the function code to control the control whose id is btnXXX on the interface.

 

From these two examples, we can guess that the "output port" in iOS actually refers to the objects in the above control's functional code.

 

In iOS, to associate an event of a control with a defined action, we can establish an association through Interface Builder or code. In this article, we focus on the first method.

Like the action, we also need to establish a connection between the output port and the control, which can also be implemented through Interface Builder or code.

 

Tip:

The Interface Builder designer is the Interface Builder, which is integrated into the Xcode tool after Xcode 4.

Open the Storyboard or xib file, and the Interface Builder designer is automatically opened.

 

 

 

4. Practice

To achieve the purpose of this article and enable the button to control the tag, we need to define the tag and connect the output port to implement the button action.

 

Click the "open auxiliary Editor" button in the upper-right corner to open the interface. In this way, you can write function code in the design field at the same time:

 

 

5. Summary

Although the application is not so tall, it is the first case we have made. Very excited.

"Although the sparrow is small and dirty", let's cheer together to make this sparrow fly more proud,

Related Article

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.