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 );}