1.属性传值
属相传值一般从前向后,即从A到B,要传什么类型值,就在B页面定义什么样的属性
如要将一个字符串从A传到B,就在B页面设置以下属相
@property(nonatomic,retain) NSString *str ;//接受的值
在A控制器跳转方法内实现
- (void)showSecondView:(UIButton*)btn
{
SecondViewController *VC = [[SecondViewController alloc] init
];
VC.str =@"我是属性传值"
;
[self presentViewController:VC animated:YES completion:nil];
}
2.delegate
在页面B设置协议及方法
//SecondViewController.h
//设置代理
@protocol
secondViewDelegate
//代理方法
(为防止循环引用用weak修饰)
-(
void
)showMessage:(NSString *)messageStr;
@end
//SecondViewController.h
@interface
SecondViewController : UIViewController
@property
(nonatomic, weak)id<secondViewDelegate> delegate;
@end
//SecondViewController.m
- (void)backFirst:(UIButton*)btn{
[self.delegate showMessage:@"我是代理传值"];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(
void
)showName:(NSString *)messageStr{
NSLong(@"%@",messageStr);
}