传值的方式:

1、正向传值

//用属性传值

在B.h中设置一个属性

@property (nonatomic,copy)NSString *string;

然后在A.m实例化B时,

给B.string赋值

B中就可以通过string来获取A传的值

2、反向传值

//用协议传值

在B.h中创建一个协议

@protocol  getBText <NSObject>

-(void *)setAText:(NSString *)string;

@end

然后在B.h中建立代理

@property (nonatomic,assign) id<getBText> delegate;

在B.m中返回时设置

if ([_delegate respondsToSelector:@selector(setView1Text:)]) {

        [_delegate setView1Text:textView.text];

    }

然后在A.h 导入协议

A.m中,在创建B实例时同时绑定代理

 B.delegate = self;

然后新建协议中的方法setAText:

原文地址:https://www.cnblogs.com/durwards/p/4529408.html