0

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.

tiw
  • 535
  • 1
  • 6
  • 22
  • In short: I want the method to behave differently when the user logs in from different places in my app. – tiw Jul 31 '13 at 10:08

1 Answers1

1
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;
}
lakshmen
  • 28,346
  • 66
  • 178
  • 276
  • i don't have a navigation controller? – tiw Jul 31 '13 at 10:52
  • or let's say it is more complicated: storyboard starts with a normal view controller. then moves on to a SWRevealViewController (you can google it) and then, it goes to one main view controller which is embedded in a navigation, and the other buttons on the side menu go to normal view controllers – tiw Jul 31 '13 at 10:53
  • super thanks. i can now get where the call to the same delegate method comes from! – tiw Jul 31 '13 at 13:52