Search code examples
swiftsegueback-button

How I can put back button in first scene in Swift3.0?


I have two storyboard, SB_A,SB_B So when I click the button at SB_A, it call

let storyboard: UIStoryboard = UIStoryboard(name: "SB_B", bundle: nil)
        let nextView = storyboard.instantiateInitialViewController()
        self.present(nextView!, animated: true, completion: nil)

So I can see SB_B storyboard. But I can't see the back button at first scene in SB_B enter image description here

I want put back button at right scene and when I click that, back to SB_A storyboard.

How I can put back button at first scene in storyboard?


Solution

  • add these lines in SB_B viewdidload

    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(self.leftNavigationItemAction(_:)))
    }
    
    @objc func leftNavigationItemAction(_ sender: UIBarButtonItem) -> Void {
           _ = popOrDismissViewController(true)
    }
    

    try this one...