码迷,mamicode.com
首页 > 其他好文 > 详细

ObjectC 实现自定义Event

时间:2015-06-03 17:39:34      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:自定义   event   

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

SocketUtils类 子control

SocketUtils头文件


#import <UIKit/UIKit.h>
#import "AsyncSocket.h"

@interface SocketUtils : UIControl{

}

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

SocketUtils.m文件

触发事件的方法:

[self sendActionsForControlEvents:UIControlEventAlert];

使用SocketUtils的目标类

头文件

#import <UIKit/UIKit.h>
#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);
}

ObjectC 实现自定义Event

标签:自定义   event   

原文地址:http://blog.csdn.net/xundh/article/details/46348519

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!