An in-depth analysis of Uicontrol_ios in IOS

Source: Internet
Author: User
Tags uicontrol

Uievent is a collection of uitouch that is responsible for responding to touch events in iOS. The concept of a responder chain is also mentioned, in which all events have a first responder, and events can be passed down the responder chain.

Next is the Uicontrol object

Uicontrol is a subclass of UIView and, of course, a uiresponder subclass. Uicontrol are the parent class of controls such as UIButton, Uiswitch, and Uitextfield, which also contain properties and methods, but cannot directly use the Uicontrol class, which simply defines the methods that subclasses need to use.

The Uicontrol object uses a new event-handling mechanism that converts the touch events that were handled directly in the previous section into simple operations so that you do not need to care about how the user accesses the control. After the touch event arrives at the Uicontrol object (dispatched by the responder chain), in the Uiresponder method (such as Touchbegan:withevent), Uicontrol converts the standard touch event into a special control event, which is simply understood Uicontrol encapsulates complex touch events into simple, easy-to-use control events. For example, when a Uicontrol object is processed, the event that presses the button is encapsulated into a control event without having to judge the entire operation of the touch screen.

For example, a button click event: UIControlEventTouchUpInside

All we need to know is that Uicontrol first converts a touch event to a control event and then to an operation with a receive drop. All we have to do is write the code for the second conversion, which is to convert the control event into a targeted operation.

Using addTarget:action:forControlEvents

This is a method of Uicontrol that adds an event to the specified control object, for example:

[Controlobj addtarget:recepientobj Action @selector (method) frocontrolevents:uicontrolevents];

Controlobj is the control object to respond to the event;

Parameter receientobj is where the message is to be sent, generally self, usually the controller that instantiates the control object;

The action is followed by a selector that indicates how the event needs to be responded, and what the event does is actually written in the method;

The last one is the event type, which indicates what event to respond to.

Two ways to use:

1. Through the Code

Create a new button in your code, add a AddTarget:action:forControlEvents method to the button object, and then write a response method.

2. Through the visual implementation of

In the IB, hold down the control key, click the mouse from the button to drag to the corresponding. h file, the establishment of a ibaction method, in this method to write event logic can complete the event response, this method is more intuitive than the first, the development efficiency is higher.

Subsequent use of other controls in iOS, but the general principle is the same, followed by the new knowledge to use these controls, including the control of the custom style.

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.