【问题标题】:iOS - Push viewController from code and storyboardiOS - 从代码和情节提要推送 viewController
【发布时间】:2012-12-08 20:24:00
【问题描述】:

我有这个代码

 PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"PlaceView"];
 [self presentViewController:newView animated:YES completion:nil];

我可以更改视图,但我会推送此视图,因为当我返回此页面时,状态仍然存在。

我试着把这段代码:

[self.navigationController pushViewController:newView animated:YES];

但什么都不做。

谢谢

【问题讨论】:

    标签: ios uiview storyboard xcode4.5 pushviewcontroller


    【解决方案1】:

    目标-C:

    PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"storyBoardIdentifier"];
    [self.navigationController pushViewController:newView animated:YES];
    

    请注意以下几点,

    1. 您的故事板标识符正确。

    2. 根视图有导航控制器。

    斯威夫特:

    let newView = self.storyboard?.instantiateViewController(withIdentifier: "storyBoardIdentifier") as! PlaceViewController
    self.navigationController?.pushViewController(newView, animated: true)
    

    【讨论】:

    • 嗨,在目的地视图控制器中没有导航
    • @JigneshB:你连接导航控制器吗?检查第二点,2.根视图有导航控制器。
    【解决方案2】:

    用途:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"STORYBOARD_NAME" bundle:nil];
    PlaceViewController *newView = [storyboard instantiateViewControllerWithIdentifier:@"PlaceView"];
    [self presentViewController:newView animated:YES completion:nil];
    

    或者:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"STORYBOARD_NAME" bundle:nil];
    PlaceViewController *newView = [storyboard instantiateViewControllerWithIdentifier:@"PlaceView"];
    [self.navigationController pushViewController:newView animated:YES];
    

    【讨论】:

      【解决方案3】:

      Swift 3.x

      let viewController = storyboard?.instantiateViewController(withIdentifier: "storyboardIdentifier") as! UIViewController
      navigationController?.pushViewController(viewController, animated: true)
      

      【讨论】:

        【解决方案4】:

        默认情况下,Xcode 创建一个标准的视图控制器。我们首先将视图控制器更改为导航控制器。选择只需在菜单中选择“编辑器”并选择“嵌入”,然后选择“导航控制器” 步骤 1. 选择主故事板 步骤 2.单击 Xcode 应用程序顶部的“编辑器”。 第三步:点击“嵌入”

        Xcode 自动将 View Controller 与 Navigation Controller 一起嵌入。

        【讨论】:

          【解决方案5】:

          对于故事板,您应该像这样使用performSegueWithIdentifier

           [self performSegueWithIdentifier:@"identifier goes here" sender:self];
          

          【讨论】:

          • 在哪里? (抱歉不知道)
          • 你应该使用[self.navigationController pushViewController:newView animated:YES];而不是[self performSegueWithIdentifer:@"You identifier" sender:self];
          • "没有可见的@interface 声明选择器'performSegueWithIdentifer:sender'" 我有这个错误
          • 我从这个类中调用这个代码:“@interface MapViewController : UIViewController {...}”所以,这个类是 UIViewController 的子类吧?
          猜你喜欢
          • 1970-01-01
          • 2012-10-09
          • 2017-08-03
          • 2020-10-29
          • 2011-12-26
          • 2012-09-22
          • 2020-06-02
          • 2014-01-01
          • 1970-01-01
          相关资源
          最近更新 更多