• block作为属性用来做页面传值


    demo设计,A页面有一个标签和一个按钮,点击按钮进入C页面,C页面有一个按钮和一个输入框,在输入框输入内容,点击按钮可以返回A页面,A页面的标签上显示C页面输入的内容。

    A页面的代码:

    @interface ViewController ()
    @property (weak, nonatomic) IBOutlet UILabel *showLabel;
    @end
    
    @implementation ViewController
    - (void)viewDidLoad {
        [super viewDidLoad];
    }
    - (IBAction)popToBView:(UIButton *)sender {    
        CViewController *bview = [[CViewController alloc] initWithNibName:@"CViewController" bundle:nil];
        if (!bview.myblock) {
            bview.myblock = ^(NSString *TextStr){
                self.showLabel.text = TextStr;
            };
        }
        [self.navigationController pushViewController:bview animated:YES];
    }

    C页面的代码:

    .h文件:

    @interface CViewController : UIViewController
    @property (weak, nonatomic) IBOutlet UITextField *inputText;
    @property(nonatomic,copy) void (^myblock)(NSString *myText);
    @end

    .m文件:

    - (IBAction)backToA:(id)sender {    
        NSString *str = self.inputText.text;
        self.myblock(str);
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
  • 相关阅读:
    php 函数strpos()
    uploadfy api中文文档
    thinkphp + 美图秀秀api 实现图片裁切上传,带数据库
    mysql 操作用户权限
    window.location 小结)
    turn.js 图书翻页效果
    thinkphp 内置标签volist 控制换行
    js 数据类型转换
    quartz 2.2.1
    Mysql测试链接
  • 原文地址:https://www.cnblogs.com/mengdaxia117/p/5222856.html
Copyright © 2020-2023  润新知