iOS block进行页面之间传值

使用Objective-C和Swift实现iOS应用开发的技巧与实践
本文深入探讨了Objective-C和Swift两种语言在iOS应用开发中的应用,提供了实用的技巧和实战案例,帮助开发者提高开发效率和代码质量。

#import <UIKit/UIKit.h>

 

@interface FirstViewController : UIViewController

 

@property (weak, nonatomic) IBOutlet UITextField *contentTxtField;

 

@end

 

#import "SecondViewController.h"

#import "FirstViewController.h"

 

@interface FirstViewController ()

 

@end

 

@implementation FirstViewController

 

- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

}

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (IBAction)jumpToSecondBtnClick:(UIButton *)sender

{

    UIStoryboard *firstSb=[UIStoryboard storyboardWithName:@"Main" bundle:nil];

    SecondViewController *secondCtl=[firstSb instantiateViewControllerWithIdentifier:@"second"];

    [secondCtl compeleteBlock:^(NSString *string) {

        

        _contentTxtField.text=string;

        

    }];

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

    

    

}

 

@end

 

 

 

 

#import <UIKit/UIKit.h>

typedef void (^BlockPassValue) (NSString *string);

@interface SecondViewController : UIViewController

{

    BlockPassValue myBlockValue;

}

@property (weak, nonatomic) IBOutlet UITextField *valueTxtField;

-(void)compeleteBlock:(BlockPassValue)myblock;

@end

 

 

#import "SecondViewController.h"

 

@interface SecondViewController ()

 

@end

 

@implementation SecondViewController

 

- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

}

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

-(void)compeleteBlock:(BlockPassValue)myblock

{

    myBlockValue=myblock;

}

- (IBAction)backToFirstBtnClick:(UIButton *)sender

{

    

    if (myBlockValue)

    {

        myBlockValue(_valueTxtField.text);

    }

    [self.navigationController popViewControllerAnimated:YES];

}

@end

 

 

转载于:https://www.cnblogs.com/thbbsky/p/4089458.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值