一.A 页面跳转到 B 页面
1.A页面跳转
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"goto"]) {
UIViewController * view = segue.destinationViewController;
[view setValue:@"我是被传递过去的字符串君" forKey:@"str"];
[view setValue:self forKey:@"delegate"];
}
}
2.B 页面接收参数 b.m页面代码
@interface ViewtowController ()
@property (nonatomic,copy) NSString* str;
@end
- (void)viewDidLoad {
[super viewDidLoad];
_twotext.text = _str;
}
二.B页面反回A页面
1.B页面反回按钮
b页面.h 中添加代码
@protocol ViewtowDelegate
- (void)passValue:(NSString *)value;
@end
@interface ViewtowController : UIViewController
@property (weak, nonatomic) id delegate;
@end
b 页面.m 添加代码
- (IBAction)backgo:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
[_delegate passValue:@"返回值"];
}
2.A 页面添代码 a页面.h代码
#import "ViewtowController.h"
a 页面.m 代码
- (void)passValue:(NSString *)value {
_userName.text = value;
}
还有一个注意一下,A页面跳转 B 页面的时候加这句话
[view setValue:self forKey:@"delegate"];
|