//.h 文件
/**
* 类型自定义
*/
typedef void (^ReturnValueBlock) (NSString *strValue);
@interface NextViewController : UIViewController
/**
* 声明一个ReturnValueBlock属性,这个Block是获取传值的界面传进来的
*/
@property(nonatomic, copy) ReturnValueBlock returnValueBlock;
@end
=================================================================
//.m 文件
#import "NextViewController.h"
@interface NextViewController ()
@property (weak, nonatomic) IBOutlet UITextField *inputText;
- (IBAction)back:(id)sender;
@end
@implementation NextViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"第二个界面";
}
/**
* 返回上一个界面
*
* @param sender 按钮
*/
- (IBAction)back:(id)sender {
NSString *inputString = self.inputText.text;
if (self.returnValueBlock) {
//将自己的值传出去,完成传值
self.returnValueBlock(inputString);
}
[self.navigationController popViewControllerAnimated:YES];
}
@end
//.m 文件
#import "ViewController.h"
#import "NextViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *nextPassedValue;
- (IBAction)next:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
//点击按钮跳转到第二个界面
- (IBAction)next:(id)sender {
NextViewController *nvc = [[NextViewController alloc]init];
//赋值Block,并将捕获的值赋值给UILabel
nvc.returnValueBlock = ^(NSString *passedValue){
self.nextPassedValue.text = passedValue;
};
[self.navigationController pushViewController:nvc animated:YES];
}
@end
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有