A界面:ide
#import "ViewController.h" #import "SecViewController.h" [@interface](https://my.oschina.net/u/996807) ViewController ()<YingDelegate> [@property](https://my.oschina.net/property) (nonatomic , strong) NSString *YingNumber; [@end](https://my.oschina.net/u/567204) @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIButton *pushB = [[UIButton alloc]init]; [pushB addTarget:self action:@selector(pushView) forControlEvents:UIControlEventTouchUpInside]; [pushB setTitle:@"PushB" forState:UIControlStateNormal]; pushB.frame = CGRectMake(200, 200, 100, 100); pushB.backgroundColor = [UIColor orangeColor]; [self.view addSubview:pushB]; } -(void)pushView{ SecViewController *BView = [[SecViewController alloc]init]; [BView setDelegate:self]; [self presentViewController:BView animated:YES completion:^{ }]; } -(BOOL)loveHer:(BOOL)yesOrno{ return yesOrno; } -(NSString *)getToKnowHer:(NSString *)phoneNum{ return self.YingNumber = phoneNum; }
B界面:atom
#import <UIKit/UIKit.h> @protocol YingDelegate<NSObject> -(NSString *)getToKnowHer:(NSString *)phoneNum; -(BOOL) loveHer :(BOOL) yesOrno; @end @interface SecViewController : UIViewController @property (assign , nonatomic) id<YingDelegate> delegate; @end @interface SecViewController () @end @implementation SecViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UIButton *pushA = [[UIButton alloc]init]; [pushA addTarget:self action:@selector(DismissView) forControlEvents:UIControlEventTouchUpInside]; [pushA setTitle:@"BackA" forState:UIControlStateNormal]; pushA.frame = CGRectMake(200, 200, 100, 100); pushA.backgroundColor = [UIColor orangeColor]; [self.view addSubview:pushA]; } -(void)DismissView{ if ([_delegate respondsToSelector:@selector(loveHer:)]){ [_delegate loveHer:YES]; } if ([_delegate respondsToSelector:@selector(getToKnowHer:)]){ [_delegate getToKnowHer:@"189227272"]; } [self dismissViewControllerAnimated:YES completion:^{ }]; }