0
votes

in my app i wanted to show a new view controller by dismissing current view controller. here is my attempt:

@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)
        })
}

I tried doing this with this code but it show error. Error:

'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'goOrders'' *** First throw call stack: ( 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 )

But in my app there is a identifier with "goOrders". Here is it

1
check your storyboardIdentifier once, \Anbu.Karthik
@Anbu.karthik I checked it. I added an image in my question. you can see thisSarwar Jahan
You named your segue goOrders, but not the controller identifier.Matz
1. View controller with "goOrders" as identifier should be present in storyboard. 2. It should be self.present.. not vc!.present.Priyal

1 Answers

1
votes

1-You have to set goOrders id here

connection less

enter image description here

2- Don't use a new VC to present itself

connection oriented

 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)
    })

//

or present it in viewDidAppear of the presentingVC