Question

To give more specifics: I am working with FBLoginView. I am using storyboards and a separate xib file for my LoginViewController. In my app, I have a loginViewController which is a FBLoginViewDelegate. And a SettingsViewController which is a FBUserSettingsDelegate. And I have a skip button in my loginView in order to sign in as a guest instead of a facebook user.

Now what I am doing is: When the app opens, I show a Walkthrough view which includes the login view at the bottom. When the user logs in with Facebook login button, the following method gets executed automatically via facebook sdk:

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                        user:(id<FBGraphUser>)user;

in this method i am performing a segue to main view.

However people can also choose to first login as a guest, and then go to Settings, and they can still login to facebook. Which happens to execute the same method above!

But then my segue isn't recognized because I am not in the Walkthrough viewcontroller anymore. Now I am in settings view controller which is in a totally different place in the hierarchy in my storyboard.

So my question is: How can I know from which viewcontroller this method is being invoked?

I am getting this warning: Attempt to present on whose view is not in the window hierarchy!

Thank you for all your helps.

Was it helpful?

Solution

MyAppDelegate *tmpDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
id myCurrentController = tmpDelegate.myNavigationController.topViewController;
NSLog(@"%@", NSStringFromClass(myCurrentController.class));

Hope this helps..

Have a try on this:

+ (UIViewController*) topMostController
{
    UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;

    while (topController.presentedViewController) {
        topController = topController.presentedViewController;
    }

    return topController;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top