IOS 代码块传值
#import <UIKit/UIKit.h>
typedef void (^MyBlock)(NSString*);
@interface SecondViewController : UIViewController @property (retain,nonatomic)UITextField* myTextField;
@property(copy,nonatomic)MyBlock block;
-(SecondViewController*)initWithBlock:(MyBlock)block; @end #import "SecondViewController.h" @interface SecondViewController () @end @implementation SecondViewController
-(SecondViewController *)initWithBlock:(MyBlock)block
{
if (self=[super init]) {
self.block=block;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
UIButton* btnTest=[UIButton buttonWithType:UIButtonTypeRoundedRect]; btnTest.frame=CGRectMake(, , , ) ;
[btnTest setTitle:@"Test" forState:UIControlStateNormal]; [btnTest addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnTest]; UITextField* textField=[[UITextField alloc]initWithFrame:CGRectMake(, , , )];
textField.borderStyle=UITextBorderStyleRoundedRect;
[self.view addSubview:textField];
self.myTextField=textField;
}
-(void)back{
if (self.block) {
self.block(self.myTextField.text);
}
[self.navigationController popToRootViewControllerAnimated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end #import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; UIBarButtonItem* btnName=[[UIBarButtonItem alloc]initWithTitle:@"Next" style:UIBarButtonItemStyleDone target:self action:@selector(next)];
self.navigationItem.rightBarButtonItem=btnName;
// Do any additional setup after loading the view, typically from a nib.
}
-(void)next{
SecondViewController* secondVC=[[SecondViewController alloc]initWithBlock:^(NSString* str){
NSLog(@"%@",str);
self.title=str;
}];
[self.navigationController pushViewController:secondVC animated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
IOS 代码块传值的更多相关文章
- iOS 页面跳转传值,属性传值,代理传值,代码块传值,单例传值,通知传值
有时候我们在页面跳转的时候回传递相应的参数,如,你想把在第一个页面的文本框里的内容显示在第二个文本框中,或者你又想把第二个文本框中的内容改变之后到第一个页面的文本框中,所有,这个时候我们就要用到页面跳 ...
- 一篇文章看懂iOS代码块Block
block.png iOS代码块Block 概述 代码块Block是苹果在iOS4开始引入的对C语言的扩展,用来实现匿名函数的特性,Block是一种特殊的数据类型,其可以正常定义变量.作为参数.作为返 ...
- [转]iOS代码块Block
代码块Block是苹果在iOS4开始引入的对C语言的扩展,用来实现匿名函数的特性,Block是一种特殊的数据类型,其可以正常定义变量.作为参数.作为返回值,特殊地,Block还可以保存一段代码,在需要 ...
- iOS代码块block使用
代码块的本质是和其他的变量类似,不同的是,代码块存储的数据是一个函数体.使用代码块,你可以像调用其他标准函数一样的调用,可以传入参数,并得到返回值. 脱字符是代码块的语法标记.下图表示代码块的 ...
- IOS 代码块
1.关系式表示 <returnType>(^BlockName)(list of arguments)=^(arguments){body;};
- iOS--页面间的代理传值(属性、代理(委托)、代码块、单例、通知)
(一)属性传值 (二)代理(委托)传值 代理传值 适用于 反向传值 (从后往前传) 1.1 创建协议 及协议方法 在反向传值的页面(SecondViewController)中 1.2 创建协议类型的 ...
- IOS学习4——block代码块
本文转载自:iOS开发-由浅至深学习block 一.关于block 在iOS 4.0之后,block横空出世,它本身封装了一段代码并将这段代码当做变量,通过block()的方式进行回调.这不免让我们想 ...
- 微信小程序富文本渲染组件html2wxml及html2wxml代码块格式化在ios下字体过大问题
1.组件使用: 之前微信小程序的富文本渲染组件用的wxParse,对普通富文本确实可以,但是对于代码格式pre标签则无法使用. 下面这个html2wxml很不错,可以支持代码高亮. 详细文档:http ...
- IOS开发之----代码块的使用(二)
iOS4引入了一个新特性,支持代码块的使用,这将从根本上改变你的编程方式.代码块是对C语言的一个扩展,因此在Objective-C中完全支持.如果你学过Ruby,Python或Lisp编程语言,那么你 ...
随机推荐
- mysql <-> sqlite
在做程序时,sqlite数据很方便.用mysql数据导出到sqlite的步骤:(用csv文件过渡) ------------------------------- 先导出到csv文件 ------ ...
- How to configure Veritas NetBackup (tm) to write Unified and Legacy log files to a different directory
Problem DOCUMENTATION: How to configure Veritas NetBackup (tm) to write Unified and Legacy log files ...
- 排列 && 组合
最近编程经常遇到需要 排列&&组合(求子集) 的问题:遂整理一下. 1. 数字的排列与组合(递归):O(n!),O(nC(n,k)) * O(n) #include <stdio ...
- HEAP CORRUPTION 错误
一般是new一块内存过小, 在这个内存块上写入的内容过大, delete时出现的错误; 如: char* ptr = new char[2]; //申请了两个字节 *ptr = "1234 ...
- Apache配置简单http认证
首先要说明的是这种认证是不安全的,密码是明文传输,因此很容易被各种嗅探软件嗅探到密码,只能用于简单的认证.今天上午把ownCloud卸载了,这玩 意儿中看不中用啊,原来10M的访问速度被限制成了几百K ...
- loadrunner11遇到的问题汇总及相应的解决方案(持续更新)
1.在此界面点击Run Load Tests提示: "Can not save the license information because access to the registry ...
- linux中软链接打包、计算以及同步
目录test中存在软连接: 1.打包,参数h(将实际文件进行打包): tar zcvfPh test.tar.gz test 2.计算大小,参数L(计算的是实际文件的大小): du -sL te ...
- 用shell脚本切分task_list,并分别执行的脚本
#/bin/sh TASK_LIST=$ len=`wc -l $TASK_LIST | awk '{print $1}'` #noExce(){ ) ))'p' $TASK_LIST > $T ...
- 基于WDF的PCI/PCIe接口卡Windows驱动程序(2)-开发者需要了解的WDF中的一些重要的概念
原文出处:http://www.cnblogs.com/jacklu/p/4646601.html 本科毕业设计是这方面的工作,所以想开几篇博客来介绍使用WDF开发PCI/PCIe接口卡的驱动程序方法 ...
- C# 委托的学习
delegate int GetCalculatedValueDelegate(int x, int y); //定义是个委托实际上就是抽象一类 参数列表形式和返回值相同的函数AddCalcu ...