第一頁面?
.h 文件中
@interfaceViewController :UIViewController
@property(weak,nonatomic)IBOutletUILabel*nextPassedValue;
- (IBAction)next:(UIButton*)sender;
@end
.m文件中
@interfaceViewController()
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.navigationItem.title=@"一";
}
//pushnext
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
SecondViewController*tfVC = segue.destinationViewController;
//賦值Block爆惧,并將捕獲的值賦值給UILabel
tfVC.returnValueBlock= ^(NSString*passedValue)
{
self.nextPassedValue.text= passedValue;
};
}
- (IBAction)next:(UIButton*)sender
{
[self performSegueWithIdentifier:@"pushnext"sender:self];
}
第二個頁面
.h
//自定義類型
typedefvoid(^ReturnValueBlock) (NSString*strValue);
@interfaceSecondViewController :UIViewController
//聲明一個ReturnValueBlock屬性狸页,這個Block是獲取傳值的界面?zhèn)鬟M來的
@property(nonatomic,copy)ReturnValueBlockreturnValueBlock;
@end
.m
@interfaceSecondViewController()
- (IBAction)back:(UIButton*)sender;
@property(weak,nonatomic)IBOutletUITextField*inputText;
@end
@implementationSecondViewController
- (void)viewDidLoad
{
[superviewDidLoad];
self.navigationItem.title=@"二";
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)back:(UIButton*)sender
{
NSString*inputString =self.inputText.text;
if(self.returnValueBlock) {
//將自己的值傳出去,完成傳值
self.returnValueBlock(inputString);
}
[self.navigationControllerpopViewControllerAnimated:YES];
}