Search code examples
iosuinavigationcontrollerswift2uistoryboardsegue

UINavigationController returning nil


we already have same questions where UINavigationController is returning nil but they all are related to segues's like this but mine question is a bit different :

in my TableViewController i embedded a UINavigationController and from my tableView I'm opening another ViewController (in this viewController navigationController is nil)

MY STORYBOARD : enter image description here

The strange is thing is that if i select first or last row of my tableView everything works fine (navigationController does not returns nil) but when i select any other row it returns nil

I'm using navigationBar in ViewWillAppear and ScrollViewDidScroll :

override func viewWillAppear(animated: Bool) {

    hairLine.hidden = true
    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
    self.navigationController?.navigationBar.shadowImage = UIImage()
    self.navigationController?.navigationBar.translucent = true
    self.navigationController?.view.backgroundColor = UIColor.clearColor()
    self.navigationController?.navigationBar.backgroundColor = UIColor.clearColor()
    self.navigationController?.navigationBar.tintColor = UIColor.blackColor()

}

Do anybody knows whats wrong here ?


Solution

  • I think you have joined the segue directly from prototype cell instead of viewcontroller. Join segue betwween controller to controller not from any UI component. Override prepareForSegue method.