如何使用以编程方式创建的UINavigationController推送到新视图?

时间:2014-04-15 05:11:19

标签: ios xcode uinavigationcontroller navigationcontroller

我尝试从这个网站唱很多但没有得到结果。现在我打开这样的新视图:

//(I call this code from View called MainReportView)
InfoController *info = (InfoController *)[self.storyboard instantiateViewControllerWithIdentifier:@"InfoController"];

info.login = login;
info.password = password;

[self presentViewController:info animated:YES completion:nil];

所有工作都很好,但是当我回到他身边时,我希望以前的View处于相同的状态。人们说使用NavigationController并推送给他,但这是一个问题。我将NavigationController添加到storyboard(到MainReportView)并尝试将代码更改为:

 [self pushViewController:info animated:YES completion:nil];

但没有任何反应,查看未打开,请帮助我如何以编程方式在此代码中添加NavigationController并使用push打开我的InfoController?谢谢 ! (我使用Xcode 5和iOS 7 + Storyboard)

解决方案 - 对于iOS7,请使用prepareForSegue和此tutorial

2 个答案:

答案 0 :(得分:5)

enter image description here

UIStoryboard *MainStoryboard = [UIStoryboard storyboardWithName:@"Main"
                                                         bundle: nil];
InfoController *info=[MainStoryboard instantiateViewControllerWithIdentifier:@"InfoController"];
[self.navigationController pushViewController:info animated:YES completion:nil]; 

full step by step guide

答案 1 :(得分:1)

在导航控制器中按下新视图控制器,如下所示:

InfoController *info = (InfoController *)[self.storyboard instantiateViewControllerWithIdentifier:@"InfoController"];
[self.navigationController pushViewController:info animated:YES completion:nil];