swift4:关闭当前视图控制器并显示另一个没有navigationController

时间:2018-04-23 07:22:52

标签: ios uiviewcontroller swift4 xcode9

在我的应用程序中,我想通过关闭当前视图控制器来显示新的视图控制器。这是我的尝试:

@IBAction func go_back_btn_pressed(_ sender: UIButton) {

    self.dismiss(animated: true, completion: {
        let vc = self.storyboard?.instantiateViewController(withIdentifier: "goOrders")
        vc!.present(vc!, animated: true, completion: nil)
        })
}

我尝试使用此代码执行此操作,但它显示错误。错误:

  

'NSInvalidArgumentException',原因:'Storyboard()不包含带有标识符'goOrders'的视图控制器   ***第一次抛出调用堆栈:   (       0 CoreFoundation 0x000000010eeab1e6 exceptionPreprocess + 294       1 libobjc.A.dylib 0x000000010e540031 objc_exception_throw + 48       2 UIKit 0x00000001105f33eb - [UIStoryboard instantiateInitialViewController] + 0       3 ProArt 0x000000010d5483c0 _T06ProArt25SelectPhotoViewControllerC19go_back_btn_pressedySo8UIButtonCFyycfU_ + 192       4 ProArt 0x000000010d549e3d _T06ProArt25SelectPhotoViewControllerC19go_back_btn_pressedySo8UIButtonCFyycfU_TA + 13       5 ProArt 0x000000010d4efd7d _T0Ieg_IeyB_TR + 45       6 UIKit 0x000000010fe4fd02 - [UIPresentationController transitionDidFinish:] + 1346       7 UIKit 0x00000001100d3f00 - [_ UICurrentContextPresentationController transitionDidFinish:] + 44       8 UIKit 0x000000010fe53b72 __56- [UIPresentationController runTransitionForCurrentState] _block_invoke.436 + 183       9 UIKit 0x0000000110a37274 - [_ UIViewControllerTransitionContext completeTransition:] + 102       10 UIKit 0x000000010fe4caee - [UITransitionView notifyDidCompleteTransition:] + 251       11 UIKit 0x000000010fe4c765 - [UITransitionView _didCompleteTransition:] + 1397       12 UIKit 0x000000010fe4ed9c - [UITransitionView _transitionDidStop:finished:] + 104       13 UIKit 0x000000010fd72f09 - [UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 343       14 UIKit 0x000000010fd7354c - [UIViewAnimationState animationDidStop:finished:] + 293       15 UIKit 0x000000010fd73600 - [UIViewAnimationState animationDidStop:finished:] + 473       16 QuartzCore 0x000000010fb277a9 _ZN2CA5Layer23run_animation_callbacksEPv + 323       17 libdispatch.dylib 0x0000000113c4f848 _dispatch_client_callout + 8       18 libdispatch.dylib 0x0000000113c5a92b _dispatch_main_queue_callback_4CF + 628       19 CoreFoundation 0x000000010ee6dc99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9       20 CoreFoundation 0x000000010ee31ea6 __CFRunLoopRun + 2342       21 CoreFoundation 0x000000010ee3130b CFRunLoopRunSpecific + 635       22 GraphicsServices 0x00000001174e7a73 GSEventRunModal + 62       23 UIKit 0x000000010fcde0b7 UIApplicationMain + 159       24 ProArt 0x000000010d52d6f7 main + 55       25 libdyld.dylib 0x0000000113ccc955 start + 1   )

但是在我的应用程序中有一个带有“goOrders”的标识符。这是它

1 个答案:

答案 0 :(得分:1)

1 - 您必须在此设置 goOrders ID

少连接

enter image description here

2-不要使用新的VC来展示自己

面向连接

 self.dismiss(animated: true, completion: {
     let vc = self.storyboard?.instantiateViewController(withIdentifier: "goOrders")

     // if it will be the root
         UIApplication.shared.keyWindow?.rootViewController?.present(vc!, animated: true, completion: nil)
    })

//

或在presentationVC的viewDidAppear中显示它