【问题标题】:How to push to new View with programatically created UINavigationController?如何推送以编程方式创建的 UINavigationController 的新视图宽度?
【发布时间】:2014-04-15 05:11:18
【问题描述】:

我尝试了这个网站的许多歌曲,但没有得到结果。现在我像这样打开新视图:

//(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 添加到情节提要(到 MainReportView)并尝试将代码更改为:

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

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

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

【问题讨论】:

  • 试试这个[self.NavigationController pushViewController:info animated:YES completion:nil];
  • [self.navigationcontroller pushViewController:info animated:YES completion:nil];
  • 如果你使用storyBoard然后做,'Perform segue With Identifier' 其他明智的上层评论对你有用。我想补充一点,如果您使用 XIB,那么执行“Self.NavigationController PushViewControllerWithNibName:YorXibName”。
  • 您检查过该信息吗!= nil? info 是 UIViewController 的子类吗?
  • 是的,你应该使用 UINavigationController

标签: ios xcode uinavigationcontroller navigationcontroller


【解决方案1】:

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

【讨论】:

  • 我做同样的事情但不工作(我在故事板中拥有的东西 - storyboard screenshot
  • 请附上有问题的截图。
  • 无法添加截图,我今天注册了。
  • InfoController *info = (InfoController *)[self.storyboard instantiateViewControllerWithIdentifier:@"InfoController"]; [自我presentViewController:信息动画:是完成:无];这段代码运行良好。但我需要推动。
  • 用于推送视图控制器... [self.navigationController pushViewController:info animated:YES completion:nil];
【解决方案2】:

像这样在导航控制器中推送新的视图控制器:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 2012-10-21
    相关资源
    最近更新 更多