iOS block进行页面之间传值
2014-11-11 14:46
435 查看
#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
![](http://images.cnitblog.com/blog/457309/201411/111445301008957.png)
@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
![](http://images.cnitblog.com/blog/457309/201411/111445301008957.png)
![](http://images.cnitblog.com/blog/457309/201411/111445446477169.png)
相关文章推荐
- iOS页面之间传值的方式(NSUserDefault/Delegate/NSNotification/Block)
- ios 页面之间的传值:属性传值,代理传值,block传值
- iOS中详解Block作为property属性实现页面之间传值
- ios 利用Block进行两个页面传值
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS 属性传值 Block传值 两个ViewController之间的
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面之间传值-----delegate的运用
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- IOS block 块实现简单的页面跳转传值
- iOS页面间传值的方式 (Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault)
- 使用Block来进行页面间的传值
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- iOS 视图之间传值(二)Block传值
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- IOS页面之间通过委托(协议)传值
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)