繁体   English   中英

关闭当前的UIViewcontroller并呈现一个新的UiViewController

[英]dismiss current UIViewcontroller and present a new UiViewController

我打算关闭我当前的UIViewController并呈现给一个新的UIViewController

我使用了以下代码

 let newViewController: ViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
 self.presentViewController(newViewController, animated: false, completion: {
         self.dismissViewControllerAnimated(false, completion: nil)
    })

它给出了以下错误

2016-06-04 11:40:59.864 myApp [851:117649]试图解雇
演示控制器已经过渡。 (<_UIFullscreenPresentationController:0x1703e6900>)2016-06-04 11:40:59.878 ePassBook [851:117649]没有设置transitionViewForCurrentTransition,演示控制器在演示期间被解雇了? (<_UIFullscreenPresentationController:0x1703e6900>)

使用此代码,

目标C代码:

[self.navigationController presentViewController:newViewController animated:NO completion:^{
    dispatch_after(0, dispatch_get_main_queue(), ^{
        [self.navigationController dismissViewControllerAnimated:NO completion:nil];
    });
}];

SWIFT代码:

self.navigationController?.presentViewController(newViewController, animated: false, completion: { () -> Void in
            dispatch_after(0, dispatch_get_main_queue(), { () -> Void in
                self.navigationController?.dismissViewControllerAnimated(false, completion: nil)

            })
        })

希望它有所帮助

尝试这个代码我觉得它很有帮助。

Objective-C的

[self.navigationController presentViewController:newViewController animated:NO completion:^{
    dispatch_async(dispatch_get_main_queue(), ^(void){
    //Run UI Updates

        [self.navigationController dismissViewControllerAnimated:NO completion:nil];
    });
}];

迅速

self.navigationController?.presentViewController(newViewController, animated: false, completion: { () -> Void in
           dispatch_async(dispatch_get_main_queue()) {
                self.navigationController?.dismissViewControllerAnimated(false, completion: nil)

        }
    })

你首先需要解雇当前存在的viewcontroller然后你只呈现另一个,因为你一次不能呈现两个viewcontrollers所以,你的代码应该像,

  self.dismissViewControllerAnimated(false) { () -> Void in

        self.presentViewController(newViewController, animated: true, completion: nil)

    }

如果您使用navigation controller则在navigation controller上显示或关闭VC

按评论中的要求更新:

举个例子,

你有三个View控制器说A,B和C,目前提供的viewController是C,如A - > B - > C.

现在你要解雇C并提出新的D然后你必须做出B的实例,因为你正在解雇C,所以自我意味着什么。 这是零。

所以你应该让B的实例说b并在那个b上呈现D.

就像是,

 self.dismissViewControllerAnimated(false) { () -> Void in

        b.presentViewController(d, animated: true, completion: nil)

    }

如果您使用的是导航控制器,那应该是,

   b.navigationController.presentViewCon.....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM