有时候在使用 storyboard 开发的时候会碰到传值等,这时要获取某个跳转的 Controller, 然后使用属性传值, 所以需要获取某个Controller,不能从新 alloc,因为从新alloc后的就不是要传值的那个了
下面,使用几行可以获取某个Controller
//点击button跳转
- (IBAction)buttonAction:(id)sender {
// 1.先创建 Storyboard 对象
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
// 2.获取 Storyboard 上的VC前,此Controller先设置Identifier,有了Identifier才能获取到想要的Controller.
ThreeViewController *threeVC = (ThreeViewController *)[storyboard instantiateViewControllerWithIdentifier:@"ThreeViewController"];
//获取到后就可以赋值了
threeVC.name = @"刘德华";
// 跳转
[self.navigationController pushViewController:threeVC animated:YES];
}
获取 storyboard 上的 Controller
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.