IOS--代理传值

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


A页面

#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



阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_17007915/article/details/49893783
文章标签: IOS代理传值
个人分类: 页面传值
想对作者说点什么? 我来说一句

iOS代理传值

2015年11月02日 35KB 下载

SelectCity

2016年09月30日 126KB 下载

iOS开发逆向传值之代理传值

2014年09月06日 42KB 下载

没有更多推荐了,返回首页

不良信息举报

IOS--代理传值

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭