FAPanels icon indicating copy to clipboard operation
FAPanels copied to clipboard

How to get topview navigation in Appdelegate ?

Open isaacraja15 opened this issue 5 years ago • 5 comments

Hi Bro, I try your Menu Its working Good . Great Job I have one Problem . I need top view controller / Current View Controller how to i get ?


if var topController = UIApplication.shared.keyWindow?.rootViewController {
            while let presentedViewController = topController.presentedViewController {
                topController = presentedViewController
            }
            print(topController)
            // topController should now be your topmost view controller
        }

I try this method its showing <menu.FAPanelController: 0x102014e00> i need Current View Controller not this one Thank you screenshot 2018-12-04 at 6 15 59 am

Isaac

isaacraja15 avatar Dec 04 '18 00:12 isaacraja15

Hey, Thanks.

You can use following function of FAPanels but you need to update it little bit.

    func isTopVC(_ root: UIViewController?) -> Bool {
        
        if root is UINavigationController {
            let nav: UINavigationController = root as! UINavigationController
            return nav.viewControllers.count == 1
        }
        else if root is UITabBarController {
            let tab: UITabBarController = root as! UITabBarController
            return  isTopVC(tab.selectedViewController!)
        }
        return root != nil
    }

To get the topViewController just return the root in above function in last line.

fahidattique55 avatar Dec 04 '18 01:12 fahidattique55

oh great , thanks bro, But what parameter i need to pass ? i'm using bluetooth BLE background service so some function need view identification for reload that view and pass the data to the view .

below the code is not BLE Module . i like your menu so i need to implement in my project so i try in simple menu project . could you help me to get current viewcontroller ?

menu.zip

isaacraja15 avatar Dec 04 '18 07:12 isaacraja15

 func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        print("qq")
        if var topController = UIApplication.shared.keyWindow?.rootViewController {
            while let presentedViewController = topController.presentedViewController {
                topController = presentedViewController
            }
            print(topController)
           let isss = isTopVC(topController)
            print(isss)
            // topController should now be your topmost view controller
        }
       
       
    }

i just try this method but is showing same

qq <menu.FAPanelController: 0x102811c00> true Executing block after changing center panelVC From Left Menu rr qq <menu.FAPanelController: 0x102811c00> true rr qq <menu.FAPanelController: 0x102811c00> true

isaacraja15 avatar Dec 04 '18 07:12 isaacraja15

when you reach to FAPanelController try getting its centre view controller and check its type. I think you need that.

fahidattique55 avatar Dec 04 '18 07:12 fahidattique55

are you saying need to pass centre view controller ?


  let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let cv = storyboard.instantiateViewController(withIdentifier: "CenterVC1") as! CenterVC
           let isss = isTopVC(cv)
            print(isss)

isaacraja15 avatar Dec 04 '18 08:12 isaacraja15