main.m
#import <Foundation/Foundation.h>
import "System.h"
import "Developer.h"
int main(int argc, const char * argv[]) {
// 协议代理
// 模拟点击环境
Developer *dev = [[Developer alloc]init];
System *sys = [[System alloc]init];
warning 协议代理4 - 注册代理人
sys.delegate = dev;
// 用户点击return/系统调用方法
[sys returnHandle];
return 0;
}
System.h
#import <Foundation/Foundation.h>
warning 协议代理3 - 提供给外面实现
@protocol keyBoardHandleDelegate <NSObject>
- (void)funckionHandle;
@end
@interface System : NSObject
warning 协议代理 - 提供给外面注册
@property (nonatomic, assign) id<keyBoardHandleDelegate> delegate;
- (void)returnHandle;
@end
System.m
#import "System.h"
@implementation System
// 模拟环境 - 当用户点击之后
(void)returnHandle
{NSLog(@"点击了return!");
warning 协议代理1 - 用对象调用方法
[self.delegate funckionHandle];
}
@end
Developer.h
#import <Foundation/Foundation.h>
import "System.h"
warning 协议代理6 - 签协议
@interface Developer : NSObject<keyBoardHandleDelegate>
- (void)funckionHandle;
@end
Developer.m
#import "Developer.h"
@implementation Developer
warning 协议代理5 - 实现功能的方法
(void)funckionHandle
{NSLog(@"爆炸");
}
@end