【问题标题】:How to open a new view and killed the actual one?如何打开新视图并杀死实际视图?
【发布时间】:2016-04-11 09:03:06
【问题描述】:

我有两个视图,actualView 和 nextView。实际上在actualView中,我想打开nextView并传递一些属性(例如nextView.date = actualView.date)并杀死actualView。

我想知道是否可以?

我使用了那个代码:

NSLog(@"Views : %@",self.navigationController.viewControllers);

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
FormViewController *formView = (FormViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"formView"];
formView.delegate = self;
[self presentViewController:formView
                   animated:YES
                 completion:nil];

 [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

当我在这个“实际视图”中使用 self.navigationController.viewControllers 时,它知道它在哪里:, 但是当我在实际视图中使用 self.navigationController.viewControllers 时,它是(null)...... 那么委托可能有问题吗?

【问题讨论】:

  • segue 的问题在于它打开视图而不杀死它们。

标签: ios ipad properties viewcontroller


【解决方案1】:

您可以将两个视图与当前模态segue 连接起来,这将终止实际视图并转到下一个视图。 这里解释得很好https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/Chapters/StoryboardSegue.html

至于将值从一个视图传递到另一个视图,请查看此函数:

覆盖 func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){

    if (segue.identifier == "segue identifier connecting the 2 views") {

        let viewController = segue.destinationViewController as!  UINavigationController
        let detailview = viewController.topViewController as! nextViewViewController

        detailview.element defined in nextview = value to send

}

您可以在网上找到很多使用标识符执行 segue 的示例。这是一个很常见的问题。

【讨论】:

    【解决方案2】:

    Apple documentation 中阅读有关removeFromSuperview() 的内容

    【讨论】:

      【解决方案3】:

      您可以使用模态 Segue。 这样,当您移动到 ​​nextView 时,actualView 将被释放。

      【讨论】:

        【解决方案4】:

        我没有找到比这更简单的方法:

        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
        UIViewController *sourceViewController = self;
        UIViewController *destinationController = [mainStoryboard instantiateViewControllerWithIdentifier: @"View3"];
        UINavigationController *navigationController = sourceViewController.navigationController;
        
        // Pop to root view controller (not animated) before pushing
        [navigationController popToRootViewControllerAnimated:NO];
        [navigationController pushViewController:destinationController animated:YES];
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-01-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-02-17
          相关资源
          最近更新 更多