//第二個界面制定協議
@protocol ChuanZhiDelegate
- (void)chuanzhid;
@end
@interface ViewController2 : UIViewController
@property(nonatomic,assign)id
@end
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor cyanColor];
self.btn=[[UIButton alloc]initWithFrame:CGRectMake(70, 100, 100, 30)];
self.btn.backgroundColor=[UIColor redColor];
[self.view addSubview:self.btn];
[self.btn addTarget:self action:@selector(chuan) forControlEvents:UIControlEventTouchUpInside];
}
- (void)chuan{
if ([self.chuanzhidelegate respondsToSelector:@selector(chuanzhid)]) {
[self.chuanzhidelegate chuanzhid];
}else{
NSLog(@"代理沒有實現changeStatus:方法");
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.btn=[[UIButton alloc]initWithFrame:CGRectMake(70, 100, 100, 30)];
self.btn.backgroundColor=[UIColor redColor];
[self.view addSubview:self.btn];
[self.btn addTarget:self action:@selector(chuanzhi) forControlEvents:UIControlEventTouchUpInside];
self.view.backgroundColor=[UIColor lightGrayColor];
}
- (void)chuanzhi{
ViewController2 *vc=[[ViewController2 alloc]init];
vc.chuanzhidelegate=self;//設置為第二個界面的代理
[self.navigationController pushViewController:vc animated:YES];
}
//實現協議
- (void)chuanzhid{
NSLog(@"代理實現");
}