1.逆向传值:
由B页面向A页面传值:
B页面
#import <UIKit/UIKit.h>
@protocol PassTrendValueDelegate
-(void)passTrendValues:(NSString *)values;//定义协议与方法
@end
@interface SecondViewController : UIViewController
///定义向趋势页面传值的委托变量
@property (retain,nonatomic) id <PassTrendValueDelegate> trendDelegate;
@property (nonatomic ,strong) NSString * data;
@end
#import "SecondViewController.h"
#import "FirstViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"data=%@",self.data);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)backonclick:(id)sender {
FirstViewController * first=[[FirstViewController alloc] init];
self.trendDelegate=first;
[self.trendDelegate passTrendValues:@"huguobin"];
[self dismissViewControllerAnimated:YES completion:^{}];
}
@end
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface FirstViewController : UIViewController<PassTrendValueDelegate>{
}
@end
#import "FirstViewController.h"
#import "SecondViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
SecondViewController *second=segue.destinationViewController;
second.data=@"我是第一个页面的值";
}
#pragma mark 实现传值协议方法
-(void)passTrendValues:(NSString *)values{
NSLog(@"value=%@",values);
}
@end