2
votes

I have read about similar problems where the problem was caused by having multiple navigation controllers, but I only have one. This is my navigation flow.

VC = UIViewController, NC = UINavigationController

VC1 -modal-> NC -root-> VC2 -show-> VC3

VC1 is not embedded in a navigation controller, I'm starting that modal segue using performSegueWithIdentifier:sender:.

VC2 then is using a show segue to present VC3, which is the one where the back button is not visible. It still works though. But, it does appear if I exit to the home screen and then enters the app again, as shown here:

https://gfycat.com/VelvetyThisHamster.

Any ideas why this is happening?

edit: To make things clear: I want the button both visible and functioning (it's not that it's working that's the problem, but that it's hidden)

EDIT 2:

If I change my navigation flow to this

NC -root-> VC2 -show-> VC3

then the back button works as intended. So the question is, how can I add a regular view controller without a navigation controller before the first navigation controller? I want it before because VC1 should not have a navigation bar and VC2 should be presented modally.

3
You should hide navigation back button on view will appearKamlesh Shingarakhiya
In VC3? That makes the button both hidden and not functioning.ludvigeriksson
Could you add some code of that VC? Probably initialization and viewDidLoad?fdiaz
present modal does not embed with navigation controller, thats the reason it s not showAnbu.Karthik

3 Answers

2
votes

try this

Hidden

override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(animated)

 //use this
self.navigationItem.setHidesBackButton(true, animated: false)
//else use this

 self.navigationItem.leftBarButtonItem = nil


}

Show

override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(animated)

 //use this
self.navigationItem.setHidesBackButton(false, animated: false)
 //else
 self.navigationController.navigationItem.backBarButtonItem.enabled = TRUE

}

Update

  override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(animated)

 //use this
self.navigationItem.setHidesBackButton(false, animated: false)
 //else
   let backButton  = UIBarButtonItem(title: "leftbutton", style: UIBarButtonItemStyle.Plain, target: self, action: "buttonMethod")

  self.navigationItem.leftBarButtonItem = backButton

}



 func buttonMethod() {
    print("Perform action")
}
1
votes

I think I found the source of the problem, so I'll post it here in case someone else runs into the same problem.

The modal presentation between VC1 and NC was made from a background queue (by calling performSegueWithIdentifier:sender: in the completion handler of an NSURLSessionDataTask to be precise). By dispatching that line of code to the main queue the problem seems to disappear.

1
votes

Turn out, I had NavigationBar tint color set to "Clear". Once I changed it, the back button appeared.