码迷,mamicode.com
首页 > 移动开发 > 详细

iOS block进行页面之间传值

时间:2014-11-11 16:04:06      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   os   sp   on   2014   log   

#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

 bubuko.com,布布扣

bubuko.com,布布扣

 

iOS block进行页面之间传值

标签:blog   http   io   ar   os   sp   on   2014   log   

原文地址:http://www.cnblogs.com/thbbsky/p/4089458.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!