频道栏目
IT货架 > > 正文
iOSblock进行页面之间传值
网友分享于:Jun 12, 2018 11:39:28 PM    来源: IT货架   

#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

 

 


广告服务联系QQ:1134687142 | 网站地图

版权所有: IT货架- 内容来自互联网,仅供用于技术学习,请遵循相关法律法规. 京ICP备11030978号-1