【问题标题】:ios-How do I add a navigation controller to a project?ios-如何在项目中添加导航控制器?
【发布时间】:2014-02-05 05:39:24
【问题描述】:

我有一个项目,但在维护导航控制器(我通过界面生成器添加)时遇到了问题。我想建立一个层次结构,因为它说视图没有添加到窗口层次结构中。我可以使用 performSegueWithIdentifier 在一个视图之间移动,但第二次使用它不起作用。问题是它不允许我从一个视图移动到另一个视图。我已经阅读了有关弄乱 appdelegate 或添加 performForSegue 的内容,但我不知道如何使用它。

如果我将三个视图连接起来,如 1 -> 2 -> 3,有什么建议吗? 1 和 2 将具有 performSegueWithIdentifier。

请,谢谢!

这是我的故事板: http://s1370.photobucket.com/user/sean_cleveland1/media/Untitled_zpsc9022523.png.html?o=0

这是我的 performSegueWithIdentifier 函数:

//Used in FirstVC.
[self performSegueWithIdentifier: @"firstToSecond" sender: self];
//Used in SecondVC... this doesn't work!
[self performSegueWithIdentifier: @"secondToThird" sender: self];

【问题讨论】:

  • 你能添加一些代码和你的故事板图像吗?
  • 我更新了我的问题。我没有任何其他与导航控制器相关的代码。
  • @SeanCleveland - 你想从屏幕 3 向右移动到屏幕 1

标签: ios objective-c uinavigationcontroller appdelegate


【解决方案1】:

只需控制并从 “弹出到主屏幕” UIButton 拖动到退出(场景底部的绿色按钮) 选择在标题为 "Main" 的第一个屏幕中声明的展开方法 例如

-(IBAction)customUnwind:(UIStoryboardSegue *)sender
{

NSLog(@"Unwind successful");

}

【讨论】:

    【解决方案2】:

    首先定义你的第三个视图标识符

    - (void)segue
    {
    
        [self performSegueWithIdentifier:@"mySegue" sender:self];
    
    }
    

    只做任何条件或操作使用下面的方法

     - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        if([[segue identifier] isEqualToString:@"mySegue"]) {
    
    
        }
    }
    

    我为你创建了简单的示例项目

    https://github.com/iDevAndroid/NavigationSample

    试试这个。因为您在下一行之后执行模型事务,所以您正在使用解除模型。

    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
    {
    
    
    
        [self becomeFirstResponder];
            [self dismissViewControllerAnimated:YES completion:^{
    [self emailDelivaryedSuccessfully];
    ];
    
    }
    
    
    
    -(void)emailDelivaryedSuccessfully{
    
    
            [self performSegueWithIdentifier: @"secondToThird" sender: self];
    }
    

    【讨论】:

    • 我查看了您的程序,它按我的意愿运行,但我无法使用 pushToNavigate。我该怎么做?
    • 您无法导航到或来自哪个控制器
    • SecondViewController 到 ThirdViewController。
    • github.com/clevelanm/VideoEmailApp-copy-4 这是我的项目。我正在尝试从 SecondViewController 到 ThirdViewController
    • 你应该在邮件关闭完成后调用该方法
    【解决方案3】:

    如果您在 Storyboard 中使用 performSegueWithIdentifier:,则无需使用,只需在代码中注释 performSegueWithIdentifier:prepareForSegue: 方法并尝试。 如果您使用的是performSegueWithIdentifier:,那么您还需要实现prepareForSegue: 方法。 前任。

    [self performSegueWithIdentifier: @"firstToSecond" sender: self];
    

    //prepareforsegue方法

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        if([[segue identifier] isEqualToString:@"firstToSecond"]) {
    
            SecondViewController *destinationController = [segue destinationViewController];
           //set data if any
        }
    }
    

    【讨论】:

    • 我将它添加到 SecondVC,并将模态添加到界面构建器(带有标识符),但是警告说未使用destinationController,并且在运行时显示“警告:尝试呈现 在 上,其视图不在窗口层次结构中!"
    • 你在使用模态搜索吗?
    • 是的,我使用的是模态转场。我尝试了推送,但我的程序崩溃了。
    • 当你尝试 push segue 时会出现什么错误,理想情况下你应该使用 push segue。
    • 由于未捕获的异常'NSGenericException'而终止应用程序,原因:'找不到用于segue'secondToThird'的导航控制器。只有当源控制器由 UINavigationController 的实例管理时,才能使用 Push segues。'
    猜你喜欢
    • 2018-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-10
    • 1970-01-01
    相关资源
    最近更新 更多