当前位置: 移动技术网 > IT编程>开发语言>C/C++ > ObjectC 实现自定义Event

ObjectC 实现自定义Event

2018年04月03日  | 移动技术网IT编程  | 我要评论

城市gdp排名,元旦手抄报版面设计图大全,梁康妮

跨类的通讯,可以使用Notification,也可以使用Event。这里记录一下实现Event的方法:
首先,定义的类要从UIControl继承。

SocketUtils类 子control

SocketUtils头文件


#import 
#import "AsyncSocket.h"

@interface SocketUtils : UIControl{

}

enum {
    UIControlEventAlert=0x00000001<<25, //可以自定义的从24 到27
    UIControlEventError=0x00000001<<26
};

SocketUtils.m文件

触发事件的方法:

[self sendActionsForControlEvents:UIControlEventAlert];

使用SocketUtils的目标类

头文件

#import 
#import "WasherSocketUtils.h"
@interface Head : UIView
@property (nonatomic,strong)SocketUtils* SocketUtils;

m文件

#import "Head.h"

@implementation Head
@synthesize SocketUtils=_SocketUtils;
-(id)init{
    _SocketUtils=[[SocketUtils alloc]init];
    ///注册事件,这句是关键
    [_SocketUtils addTarget:self action:@selector(socketEvent:) forControlEvents:UIControlEventAlert];

    return [super init];
}
-(void)socketEvent:(SocketUtils*)paramSender{
    NSLog(@"event by xie:%@",paramSender);
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网