iOS开发 使用Block实现两个页面互相传值
来源:互联网 发布:淘宝客拉人广告词 编辑:程序博客网 时间:2024/06/09 17:11
RootViewController.m里
#import "RootViewController.h"
#import "SecondViewController.h"
@interface RootViewController ()
@property(nonatomic,retain)UITextField *textField;
@property(nonatomic,retain)UILabel *label;
@end
@implementation RootViewController
- (void)dealloc
{
[_labelrelease];
[_textFieldrelease];
[superdealloc];
}
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
_label = [[UILabelalloc]initWithFrame:CGRectMake(100,200, 100,30)];
_label.text =@"YES";
[self.viewaddSubview:_label];
_textField = [[UITextFieldalloc]initWithFrame:CGRectMake(100,100, 200,30)];
_textField.borderStyle =UITextBorderStyleRoundedRect;
[self.viewaddSubview:_textField];
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];
button.frame =CGRectMake(100,300, 100,30);
[button setTitle:@"OK"forState:UIControlStateNormal];
[button addTarget:selfaction:@selector(didClick:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
}
- (void)didClick:(UIButton *)button
{
SecondViewController *secondVC = [[SecondViewControlleralloc]init];
[self.navigationControllerpushViewController:secondVC animated:YES];
secondVC.myblock = ^(NSString *string){
_label.text = string;
};
secondVC.passValue = ^(UILabel *label)
{
label.text =self.textField.text;
};
[secondVC release];
}
@end
SecondViewController.h里
#import <UIKit/UIKit.h>
typedef void(^returnBlock)(NSString *);
typedef void(^passvalueBlock)(UILabel *);
@interface SecondViewController :UIViewController
@property(nonatomic,copy)returnBlock myblock;// 第二个页面传给第一个页面
@property(nonatomic,copy)passvalueBlock passValue; // 第一个页面传给第二个页面
@end
SecondViewController.m里
#import "SecondViewController.h"
@interface SecondViewController ()
@property(nonatomic,retain)UITextField *textField;
@property(nonatomic,retain)UILabel *label;
@end
@implementation SecondViewController
- (void)dealloc
{
[_labelrelease];
[_textFieldrelease];
[superdealloc];
}
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColorwhiteColor];
_label = [[UILabelalloc]initWithFrame:CGRectMake(50,200, 100,30)];
self.passValue(_label);
[self.viewaddSubview:_label];
_textField = [[UITextFieldalloc]initWithFrame:CGRectMake(50,100, 200,30)];
_textField.borderStyle =UITextBorderStyleRoundedRect;
[self.viewaddSubview:_textField];
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];
button.frame =CGRectMake(50,300, 100,30);
[button setTitle:@"OK"forState:UIControlStateNormal];
[self.viewaddSubview:button];
}
- (void)viewWillDisappear:(BOOL)animated
{
[superviewWillDisappear:animated];
self.myblock(self.textField.text);
}
- iOS开发 使用Block实现两个页面互相传值
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- IOS开发: 使用Block在两个界面之间传值(Block高级用法:Block传值)
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- iOS开发:使用Block在两个界面之间传值
- iOS开发:使用Block在两个界面之间传值
- ios 利用Block进行两个页面传值
- 使用block闭包是实现两个页面间的反向传值
- 用block实现两个页面间的传值
- iOS开发使用Block页面间传值
- 使用Block实现页面传值
- iOS开发:StoryBoard 使用Block在两个界面之间传值
- iOS开发:通过block在两个页面间传值
- OnClientTriggerClick 两个页面之间互相传值
- 两个html页面互相传值
- 数据结构 - 指针,数组,结构体
- Overlapped重叠I/O之事件通知
- ios的crash异常
- Word Search
- C++中的静态函数
- iOS开发 使用Block实现两个页面互相传值
- GCC内建函数 __builtin_return_address实现
- Android核心基础-9.Android四大组件之BroadcastReceiver
- 2.1.2 RGB Cube (about vertex output parameters) RGB立方体(关于顶点输出参数)
- Altium_Designer如何快速寻找元件和封装
- 算法数据结构之贪心算法
- 导出pdf(表格形式)
- LeetCode_path-sum
- easyUI的高级查询