文档章节

代理传值

阿元
 阿元
发布于 2017/07/05 16:28
字数 216
阅读 6
收藏 0

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

© 著作权归作者所有

共有 人打赏支持
上一篇: 十三 iOS9
下一篇: caseInsensitiveCompare
阿元
粉丝 5
博文 163
码字总数 109721
作品 0
浦东
程序员
私信 提问

暂无文章

关于SeekBar 拖动区域小的解决办法

//seekbarLayout 是seekBar对象statusSeekbar的父层布局seekbarLayout = mStatusViewLayout.findViewById(R.id.id_seekbar_layout);seekbarLayout.setOnTouchListener(new View.OnTouchL......

东街小霸王
21分钟前
0
0
python实现下载网络视频资源

项目需求: 有时候我们做爬虫的时候,需要把爬取到的视频资源保存到我们本地,以防爬取的视频链接被原来资源主人变更,所以就需要把好不容易拿到的资源永久变为自己的,就需要把视频链接下载到我们...

银装素裹
30分钟前
0
0
2.

三种ui窗口编译方式 C:\Users\hellopasswd>pyuic5 -o D:\testQtDesigner\firstMainWin.py D:\testQtDesigner\firstMainWin.ui import osimport os.pathdir ='./'def listUiFile(): ......

hellopasswd
31分钟前
0
0
写一个简单的运行Django项目的脚本

#!/bin/shecho -e "\033[32m killed original process \033[0m"project_name="tax_backend"env_name="tax_backend"echo "name = $name"ids=`ps -ef | grep "$project_name" | ......

易冥天
35分钟前
0
0
Kafka是如何解决常见的微服务通信问题的

微服务自成立以来就以不同的方式相互沟通。有些人更喜欢使用HTTP REST API,但这些API有自己的排队问题,而有些则更喜欢较旧的消息队列,比如RabbitMQ,它们带有扩展和操作方面的问题。 以K...

java菜分享
今天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部