3.利用Delegate在两个或多个ViewController之间传值
在A界面
.h文件
@protocol secondViewDelegate
-(void)passViewController:(NSString*)str;//1a.定义协议与方法
@end
@interface ViewController : UIViewController
@property(retain,nonatomic)id<secondViewDelegate>secondDelegate;//1b.定义向趋势页面传值的委托变量
@end
.m文件
SecondViewController *vc = [[SecondViewControlleralloc]init];
self.secondDelegate = vc;//设置代理
[self.secondDelegatepassViewController:@"this is a string!"];//
在B界面
.h文件
#import "ViewController.h"
@interface SecondViewController : UIViewController< secondViewDelegate>{
}
.m文件
//实现传值协议方法
-(void)passViewController:(NSString *)str{
NSLog(@"-----------%@",str);
}