美文网首页
简单的block传值(逆向)

简单的block传值(逆向)

作者: 探路者1202 | 来源:发表于2017-05-25 14:56 被阅读0次

第一页面 

.h 文件中

@interfaceViewController :UIViewController

@property(weak,nonatomic)IBOutletUILabel*nextPassedValue;

- (IBAction)next:(UIButton*)sender;

@end

.m文件中

@interfaceViewController()

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

self.navigationItem.title=@"一";

}

//pushnext

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender

{

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

SecondViewController*tfVC = segue.destinationViewController;

//赋值Block,并将捕获的值赋值给UILabel

tfVC.returnValueBlock= ^(NSString*passedValue)

{

self.nextPassedValue.text= passedValue;

};

}

- (IBAction)next:(UIButton*)sender

{

[self performSegueWithIdentifier:@"pushnext"sender:self];

}

第二个页面

.h

//自定义类型

typedefvoid(^ReturnValueBlock) (NSString*strValue);

@interfaceSecondViewController :UIViewController

//声明一个ReturnValueBlock属性,这个Block是获取传值的界面传进来的

@property(nonatomic,copy)ReturnValueBlockreturnValueBlock;

@end

.m

@interfaceSecondViewController()

- (IBAction)back:(UIButton*)sender;

@property(weak,nonatomic)IBOutletUITextField*inputText;

@end

@implementationSecondViewController

- (void)viewDidLoad

{

[superviewDidLoad];

self.navigationItem.title=@"二";

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (IBAction)back:(UIButton*)sender

{

NSString*inputString =self.inputText.text;

if(self.returnValueBlock) {

//将自己的值传出去,完成传值

self.returnValueBlock(inputString);

}

[self.navigationControllerpopViewControllerAnimated:YES];

}

相关文章

  • iOS页面间逆传值

    页面间传值有两种: 正向传值(利用属性传值就可以了,很简单) 逆向传值(有3种常用的方法) 代理传值 block传...

  • 简单的block传值(逆向)

    第一页面 .h 文件中 @interfaceViewController :UIViewController @p...

  • 《OC之Block》

    由来:温故而知新可以为师矣。 一.Block的声明 二.Block的逆向传值 1:传值方-------------...

  • block 逆向传值

    ①在后面控制器的 .h文件 中声明block //一会要传的值为NSString类型 typedefvoid(^n...

  • iOS Block逆向传值

    逆向传值的方法有很多如代理、通知、block、KVC等等。但是相对来说block是最简单方便的,前提是处理好使用b...

  • ObJective-C之利用Block逆向传值

    在iOS开发之通过代理逆向传值一文中,分析了利用代理模式来逆向传值,其实还有一些其他的方式,如通知、Block等,...

  • iOS开发之利用Block逆向传值

    在iOS开发之通过代理逆向传值一文中,分析了利用代理模式来逆向传值,其实还有一些其他的方式,如通知、Block等,...

  • iOS 传值

    页面传值 NSNotification Delegate Block 单例 一、 页面传值 最简单直接的传值方法 ...

  • iOS代理、block、通知传值

    一般正向传值基本使用属性传值,这里不多讲。如果需要逆向传值,基本使用代理和block,也可以使用通知。这些基本都会...

  • Block的简单使用之逆向传值

    想逆向传值的时候使用Block时非常方便的,当从A控制器跳转到B控制器,想从B控制器逆向传值时,只需要在B控制器的...

网友评论

      本文标题:简单的block传值(逆向)

      本文链接:https://www.haomeiwen.com/subject/soczxxtx.html