2

i have a tab bar controller, and inside that tab bar i have five view controller. i also have have a right view controller(drawer) which is on homeVC. for rightViewController i use MMDrawerController source: https://www.youtube.com/watch?time_continue=1468&v=TdKnImb4SWs. in the appdelegate . Now when the right view controller is closed, which life cycle of view controller is getting called? because i want to write a function. I have used this code on appdelegate

    let rightViewController = mainStoryboard.instantiateViewController(withIdentifier: "RightViewVC") as! RightViewVC



       UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white]

    let rightSideMenuNav = UINavigationController(rootViewController: rightViewController)
    drawerController = MMDrawerController(center:mainPage,rightDrawerViewController:rightSideMenuNav)

   // drawerController!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.panningCenterView
    drawerController!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.panningCenterView
    drawerController!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.all
    drawerController!.preferredInterfaceOrientationForPresentation = MMDrawerOpenCenterInteractionMode.full

    window?.rootViewController = drawerController
Chirag Shah
  • 3,034
  • 1
  • 30
  • 61
Gorib Developer
  • 587
  • 2
  • 13
  • 27
  • there is one block which is called when you close the drawer – Chirag Shah Jul 28 '18 at 06:04
  • which block sir? – Gorib Developer Jul 28 '18 at 06:05
  • For opening drawer i think you write this method `self.drawer?.close(.left, animated: isAnimation) { (isCompleted) in }` so when drawer successfully open then completion handler will called. – Chirag Shah Jul 28 '18 at 06:07
  • for opeining drawer i have written let appdelegate = UIApplication.shared.delegate as! AppDelegate appdelegate.drawerController?.toggle(MMDrawerSide.right, animated: true, completion: nil) – Gorib Developer Jul 28 '18 at 06:08
  • my bad checked my updated comment – Chirag Shah Jul 28 '18 at 06:10
  • actually my right view controller is the filter screen, so when i click on filter i want to show the updated search result on homescreen, but unable to send data from RightView VC to homeVC – Gorib Developer Jul 28 '18 at 06:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176923/discussion-between-chirag-shah-and-gorib-developer). – Chirag Shah Jul 28 '18 at 06:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176932/discussion-between-chirag-shah-and-gorib-developer). – Chirag Shah Jul 28 '18 at 09:30

3 Answers3

1

the viewwillApear() in homeViewController will get called when rightViewController closed.

Hitesh Agarwal
  • 1,943
  • 17
  • 21
  • Thanks for reply sir, but i am giving break point in viewwillApear() after closing the rightView controller it is not getting called – Gorib Developer Jul 28 '18 at 05:55
  • wait a minute sir – Gorib Developer Jul 28 '18 at 06:02
  • this code i have written in a button which is in the RightViewController let appdelegate = UIApplication.shared.delegate as! AppDelegate appdelegate.drawerController?.closeDrawer(animated: true, completion: nil) – Gorib Developer Jul 28 '18 at 06:06
  • actually my right view controller is the filter screen, so when i click on filter i want to show the updated search result on homescreen, but unable to send data from RightView VC to homeVC – Gorib Developer Jul 28 '18 at 06:12
1

MMDrawer provide the completion block when open,close or toggel the drawer you just need to compare the event like drawer is close or open you got the success. Here is the code

@IBAction func rightMenuButtonTapped(_ sender: Any) { 

    let appdelegate = UIApplication.shared.delegate as! AppDelegate 

    appdelegate.drawerController?.toggle(MMDrawerSide.right, animated: true){ (isCompleted) in 
            if appdelegate.drawerController?.openSide == MMDrawerSide.none 
            { 
                 print("drawer close")
                 if let objHome = appdelegate.drawerController?.centerViewController as? HomeVC{ 
                      print("Got Home VC") 
                 }  
            } 
            else if appdelegate.drawerController?.openSide == MMDrawerSide.right 
            { 
                 print("drawer open") 
            } 
     }
}
Chirag Shah
  • 3,034
  • 1
  • 30
  • 61
0

Try to print in each viewDidLoad to see the active controllers:

if let window = UIApplication.shared.delegate?.window {
    if var viewController = window?.rootViewController {
        // handle navigation controllers
        if(viewController is UINavigationController){
            viewController = (viewController as! UINavigationController).visibleViewController!
        }
        print(viewController)
    }
}

or

if self.window.rootViewController is MyViewController {
    //do something if it's an instance of that class
}
J A S K I E R
  • 1,976
  • 3
  • 24
  • 42
  • actually my right view controller is the filter screen, so when i click on filter i want to show the updated search result on homescreen, but unable to send data from RightView VC to homeVC – Gorib Developer Jul 28 '18 at 06:12
  • @GoribDeveloper, this video is 3 years old. Have you tried other solutions? What is your goal about view controllers? – J A S K I E R Jul 28 '18 at 06:27
  • Goal means sir? i have tried other possible ways, i prefer this video bcz it shows drawer with tab bar controller, that;s why – Gorib Developer Jul 28 '18 at 06:32