Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get topview navigation in Appdelegate ? #51

Open
isaacraja15 opened this issue Dec 4, 2018 · 5 comments
Open

How to get topview navigation in Appdelegate ? #51

isaacraja15 opened this issue Dec 4, 2018 · 5 comments

Comments

@isaacraja15
Copy link

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

@fahidattique55
Copy link
Owner

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.

@isaacraja15
Copy link
Author

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
Copy link
Author

 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

@fahidattique55
Copy link
Owner

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

@isaacraja15
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants