代理传值
博客专区 > 阿元 的博客 > 博客详情
代理传值
阿元 发表于8个月前
代理传值
  • 发表于 8个月前
  • 阅读 6
  • 收藏 0
  • 点赞 0
  • 评论 0

新睿云服务器60天免费使用,快来体验!>>>   

摘要: 界面A跳转B,B传值回A

A界面:


#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界面:


#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:^{
		
	}];
}

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 5
博文 151
码字总数 95488
×
阿元
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: