ObjectC implements Custom Event

Source: Internet
Author: User
Tags uicontrol

ObjectC implements Custom Event

For cross-class communication, you can use Notification or Event. Here we record the method for implementing Event:
First, the defined class must be inherited from UIControl.

Header file of the SocketUtils class sub-controlSocketUtils
# Import
  
   
# Import "AsyncSocket. h "@ interface SocketUtils: UIControl {} enum {UIControlEventAlert = 0x00000001 <25, // customizable from 24 to 27 UIControlEventError = 0x00000001 <26 };
  
SocketUtils. m file

How to trigger an event:

[self sendActionsForControlEvents:UIControlEventAlert];
Use the target Class header file of SocketUtils
#import 
  
   #import "WasherSocketUtils.h"@interface Head : UIView@property (nonatomic,strong)SocketUtils* SocketUtils;
  
M file
# Import "Head. h "@ implementation Head @ synthesize SocketUtils = _ SocketUtils;-(id) init {_ SocketUtils = [[SocketUtils alloc] init]; // register an event, this sentence is critical to [_ SocketUtils addTarget: self action: @ selector (socketEvent :) forControlEvents: UIControlEventAlert]; return [super init];}-(void) socketEvent :( SocketUtils *) paramSender {NSLog (@ "event by xie: % @", paramSender );}

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.