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编程语言,那么你 ...
随机推荐
- OAF_文件系列2_实现OAF导出CSV格式文件ExportButton(案例)
20150727 Created By BaoXinjian
- BroadcastReceiver和EventBus区别是什么
BroadcastReceiver和EventBus区别是什么?他俩都挺像的,什么时候用BroadcastReceiver,什么时候用EventBus呢? Android广播分为两个方面:广播发送者和 ...
- ios 屏幕概况
转:http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
- 49. Search in Rotated Sorted Array && Search in Rotated Sorted Array II
Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you before ...
- springMVC使用与生成序列号
springMVC使用与生成序列号 我是以springMVC的方式提供序列号 代码可以直接在项目中用 第一步:controller类 @Autowired private PkGenerator pk ...
- ES6中的Class
对于javascript来说,类是一种可选(而不是必须)的设计模式,而且在JavaScript这样的[[Prototype]] 语言中实现类是很蹩脚的. 这种蹩脚的感觉不只是来源于语法,虽然语法是很重 ...
- C# 操作pem 文件
using Dscf.Bpl.InformationAuditBpl; using Dscf.Bpl.ProductBpl; using Dscf.Global.CommonAduit; using ...
- Hadoop HDFS编程 API入门系列之路径过滤上传多个文件到HDFS(二)
不多说,直接上代码. 代码 package zhouls.bigdata.myWholeHadoop.HDFS.hdfs6; import java.io.IOException;import jav ...
- XidianOJ 1177 Counting Stars
题目描述 "But baby, I've been, I've been praying hard, Said, no more counting dollars We'll ...
- UART UVM验证平台平台搭建总结
tb_top是整个UVM验证平台的最顶层:tb_top中例化dut,提供时钟和复位信号,定义接口以及设置driver和monitor的virual interface,在intial中调用run_te ...