最简单的属性传值
1、先建立两个 FirstViewController、SecondViewController 视图
2、FirstViewController
(1).h里面不作改变
(2).m里面添加一个头文件 #import "SecondViewController.h"
//添加一个按钮
//跳转
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnsetTitle:@"跳入第二个界面" forState:UIControlStateNormal];
[btnsetBackgroundColor:[UIColor blackColor]];
btn.frame = CGRectMake((self.view.bounds.size.width-200)/2, 200, 200, 50);
[self.view addSubview:btn];
[btnaddTarget:self action:@selector(secondView)
forControlEvents:UIControlEventTouchUpInside];//添加事件
-(void)secondView{
// 事件函数
SecondViewController *secondVC = [[SecondViewController alloc] init];
secondVC.gain = @“我拿到值了!”;//赋值
secondVC.hidesBottomBarWhenPushed = YES;//隐藏底部导航栏
[self.navigationController pushViewController:secondVC animated:YES];
}
2、SecondViewController界面
(1) .h
@property (nonatomic, strong) NSString *gain;//取值
(2).m
NSLog(@"我拿到的值 = %@",self.gain);//查看是有将值传入
以上是我个人简单的传值方法
若有问题,请帮忙指出,谢谢观看!