从BViewController传到AViewController
在BViewController.h中
#import <UIKit/UIKit.h>
@protocol IDDelegate <NSObject>
- (void)setIDValue:(NSString *)value;
@end
@interface BViewController : UIViewController
@end
在BViewController.m中
#import "BViewController.h"
@interface BViewController ()
@property(nonatomic, retain) id<IDDelegate> idDelegate; // 注册一个代理
@end
然后在需要跳转的时候
AViewController *a = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2];
self.idDelegate = a; // 这里和AViewController 进行交互,下一句代码就是对应的赋值
[self.idDelegate setIDValue:stringValue];
[self.navigationController popToViewController:qvc animated:true];
在AViewController.h中
#import "BViewController.h" // 导入协议
@interface AViewController : UIViewController<IDDelegate>// 遵守协议
@property (strong, nonatomic) UITextField *contactIdField;
- (void)setIDValue:(NSString *)value;
@end
在AViewController.m中
- (void)setIDValue:(NSString *)value // 实现方法
{
self.contactIdField.text = value ;
}