美文网首页
block逆传值页面间的

block逆传值页面间的

作者: xh_0129 | 来源:发表于2016-10-14 15:58 被阅读0次

@interface SecondViewController : UIViewController

@property (nonatomic,copy) void(^stringBlock)(NSString *text);

@end

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {

[super viewDidLoad];

UIButton *b = [[UIButton alloc]initWithFrame:CGRectMake(60, 80, 100, 32)];

b.backgroundColor = [UIColor blueColor];

[b addTarget:self action:@selector(pop) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:b];

}

- (void)pop {

//传值

self.stringBlock(@"第二个值");

[self.navigationController popViewControllerAnimated:YES];

}

//需要接受值的地方,即push到SecondViewController的地方

SecondViewController *send = [[SecondViewController alloc]init];

send.stringBlock = ^(NSString *text) {

label.text = text;

NSLog(@"%@",label.text);

};

[self.navigationController pushViewController:send animated:YES];

相关文章

  • block逆传值页面间的

    @interface SecondViewController : UIViewController@proper...

  • IOS 界面之间传值总结

    iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单...

  • Block页面间传值

    不废话,上代码 》》》 1、先说下实现的过程:A到B,B带值到A,A打印或者显示。 2、实现的思路:A调用B声明的...

  • iOS 传值

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

  • iOS页面间逆传值

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

  • ioS 页面(代理、通知、block、单例、属性)传值

    iOS 页面(代理、通知、block、单例、属性)传值 一、传值分类 页面传值基本分为两种:正向传值和反向传值。 ...

  • iOS 页面(代理、通知、block、单例、属性)传值

    iOS 页面(代理、通知、block、单例、属性)传值 一、传值分类 页面传值基本分为两种:正向传值和反向传值。 ...

  • Block开发使用场景(传值)

    通常我们传值分为顺传和逆传:顺传:给需要传值的对象定义属性来传值。逆传:代理, 通知,单例,block等。此篇文章...

  • swift 闭包传值

    场景:A页面跳转到B页面,B页面返回到A页面,(B页面给A页面传值) B页面逻辑:创建block,声明变量,传值 ...

  • 页面间的block传值(B -> A)

    //在B页面的.h中写一个指针函数(结构体),带参数,用户进行传值//在B页面的.h中声明一个指针类型的变量//例...

网友评论

      本文标题:block逆传值页面间的

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