#import <UIKit/UIKit.h>
@protocol TwoViewDelegate <NSObject>
- (void)changeValue1;
- (void)changeValue2;
@end
@interface GCTwoViewController : UIViewController
@property (nonatomic,unsafe_unretained) id<TwoViewDelegate>delegate;
@end
在 GCTwoViewController.m文件中
[self.delegate changeValue1];
[self.delegate changeValue2];
在界面ViewController1和ViewController2同时成为GCTwoViewController的代理
在ViewController1 中
GCTwoViewController.delegate = self;
在ViewController2中
GCTwoViewController.delegate = self;
是因为注册代理的时候传了self给代理 ,代理知道被谁调,还是一对一的关系。所以没问题
代理可以被多个界面调用,但是保证注册代理传入的self是唯一的。
使用细节
delegate 中 [self.delegate updateAlert];
在其他使用的界面中 timer.delegate = self; //设置代理实例
delete可以被多个类代理 但是进来的时候是一一对应的 就可以了
就是在一个self下只有一个delegate