IOS Study Notes 10-uicontrol object details

Source: Internet
Author: User
Tags uicontrol

In the previous article, we talked about uitouch and uievent events. In a brief review, uievent is a collection of uitouch and is responsible for responding to touch events in IOS. In addition, the concept of the responder chain is also mentioned. In iOS, all events have the first responder, and the events can be passed down along the responder chain.


The following is the uicontrol object.

Uicontrol is a subclass of uiview. It is also a subclass of uiresponder. Uicontrol is the parent class of controls such as uibutton, uiswitch, and uitextfield. It also contains some attributes and methods, but cannot directly use the uicontrol class, it only defines the methods required by subclass.


The uicontrol object adopts a new event processing mechanism to convert the touch events directly processed in the previous section into simple operations, so that you do not need to care about the specific methods of the user access control. After a touch event arrives at the uicontrol object (dispatched by the responder chain), In the uiresponder method (such as touchbegan: withevent), uicontrol converts a standard touch event to a special control event, A simple understanding is that uicontrol encapsulates complex touch events into simple and easy-to-use control events. For example, after processing through the uicontrol object, the event that presses the button is encapsulated into a control event, instead of judging the entire operation process of the touch screen.

For example, click the button event: uicontroleventtouchupinside


What we need to know is that uicontrol first converts a touch event to a control event, and then converts it to an operation with a receipt and release. We only need to write the code for the second conversion, that is, to convert the control event to a targeted operation.


Use addtarget: Action: forcontrolevents

This is a method of uicontrol to add events to the specified control object. For example:

[Controlobj addtarget: policientobj action @ selector (method) frocontrolevents: uicontrolevents];

Controlobj is the control object to respond to events;

The receientobj parameter refers to the message to be sent, which is generally self, which usually refers to the Controller of the instantiated control object;

Action is followed by a selector, indicating the method that the event needs to respond to. What the event does is actually written in this method;

The last one is the event type, indicating the event to be responded.


Two methods are used:

1. Code

Create a new button in the code, add the addtarget: Action: forcontrolevents Method to the button object, and write the response method.


2. Visualization

In IB, hold down the control key and click the mouse to drag from the button to the corresponding one. in the H file, an ibaction method is created, in which event logic can be compiled to complete event response. This method is more intuitive and more efficient than the first method.


Other controls in IOS will be used later, but the general principles are the same. These controls will be used in combination with new knowledge, including custom controls.

To join our QQ group or public account, see: Ryan's
Zone public account and QQ Group


Welcome to my Sina Weibo chat: @ Tang Ren _ Ryan

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.