0

i'm using swift4, this is my design structure the structure first view controller is SWRevealViewController has sw_front segue to UITabBarViewController, and sw_rear to UITableViewController

i have back button and menu button in every view controller, I want to use the default action of back button in each view controller baut i didn't know how, is there any way that solve this problem

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Al-shimaa Adel
  • 767
  • 1
  • 10
  • 26
  • you need to create `BaseViewController` in that you need to write back button and menu button code and inherit to every controller. – AbecedarioPoint May 31 '18 at 09:01
  • @AbecedarioPoint back button with which segue I have four different segue types tabs, reveal view controller push controller, reveal view controller set controller, and push segue ?? – Al-shimaa Adel May 31 '18 at 09:07

1 Answers1

0
    class SuperViewController: UIViewController {
func goBackNavigationBarItem(){
        //Left Button - Navigation bar
        let leftButton = UIBarButtonItem(image: UIImage(named: imgName)?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(SuperViewController.btnBackClicked(_:)))

        self.navigationItem.leftBarButtonItem = leftButton;
    }

func btnBackClicked(_ sender:UIButton!){
    // whatever action You want on back button 
}
}

make your viewController child of SuperViewController and Call this function goBackNavigationBarItem() in viewDidLoad() of every view controller Like this..

class AnyVC: SuperViewController{

override func viewDidLoad() {
        super.viewDidLoad()
        goBackNavigationBarItem()
    }
}

Hope this help.

Divya Thakkar
  • 212
  • 3
  • 13
  • thank you, but my problem is the action of back button for example in bottom view controller what would the back button action be as i navigated to it with segue reveal view controller push controller – Al-shimaa Adel May 31 '18 at 09:57
  • https://stackoverflow.com/questions/25358482/unwind-segue-from-navigation-back-button-in-swift check this.. – Divya Thakkar May 31 '18 at 10:15