• 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(120, 130, 80, 30) ;
        [btnTest setTitle:@"Test" forState:UIControlStateNormal];
        
        [btnTest addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btnTest];
        
        UITextField* textField=[[UITextField alloc]initWithFrame:CGRectMake(120, 80, 80, 30)];
        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
  • 相关阅读:
    Asp.Net MVC Control向View传值
    初学MyBatis.net
    win10更新后,可以远程桌面ping也没问题,但是无法访问共享文件夹的解决方法
    我的常用自定义函数
    获取图片大小
    python获取文件路径、文件名、后缀名的实例
    Python-Selenium中chromeDriver限制图片和Javascript加载
    精华 selenium_webdriver(python)调用js脚本
    安装程序无法使用现有分区 因为它没有包含所需的空间?怎么办?
    我们无法创建新的分区 也找不到现有的分区 已解决【亲测有效】
  • 原文地址:https://www.cnblogs.com/mojiewei/p/5050337.html
Copyright © 2020-2023  润新知