0

I have a barButtonItem and I am performing an action from that to show another viewController(first in hierarchy), but it gets hard, cause if I try

self.dismissViewControllerAnimated(true, completion:nil)

it gets me not that viewController, that I need. also, if I am doing

    var navigCont = UINavigationController(rootViewController: destinationViewController)
    navigCont.navigationBar.barTintColor = instaColor
    navigCont.navigationBar.tintColor = UIColor.whiteColor()
    navigCont.navigationBar.translucent = false
    navigCont.presentViewController(destinationViewController, animated: true, completion: nil)

it gets error, cause

Application tried to present modally an active controller 

So I am stucked, and I don't know how to present my VC right. Any advices?

Code cracker
  • 3,105
  • 6
  • 37
  • 67
Pavel Zagorskyy
  • 443
  • 1
  • 4
  • 20

2 Answers2

0

You are trying to present destinationViewController on a navigation controller with rootViewController set to destinationViewController itself. Create a new rootViewController for your navigationController and try below code if it works:

var mainViewController = UIViewController(nibName: "MainViewController", bundle: nil)
var navigCont = UINavigationController(rootViewController: mainViewController)
navigCont.navigationBar.barTintColor = instaColor
navigCont.navigationBar.tintColor = UIColor.whiteColor()
navigCont.navigationBar.translucent = false
navigCont.presentViewController(destinationViewController, animated: true, completion: nil)
atulkhatri
  • 10,896
  • 3
  • 53
  • 89
0

Answer was simply to create segue and make action for this segue in storyboard. The goal was - create a sequel without a storyboard item. Actually this isn't a correct answer on my question, but this way of solving helped.

How to perform Unwind segue programmatically?

Community
  • 1
  • 1
Pavel Zagorskyy
  • 443
  • 1
  • 4
  • 20