简体   繁体   English

无法从应用程序委托调用View Controller方法

[英]Can't call View Controller method from app delegate

I'm trying to build the sample app from facebook iOS SDK but I'm using storyboards so it's a little different. 我正在尝试从facebook iOS SDK构建示例应用程序,但是我正在使用情节提要,因此有些不同。

I'm doing this check in my AppDelegate.m application didFinishLaunchingWithOptions: 我正在我的AppDelegate.m应用程序didFinishLaunchingWithOptions:进行此检查didFinishLaunchingWithOptions:

 if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
    // To-do, show logged in view
} else {
    // No, display the login page.
    [self showLoginView];
}

return YES;

I've created a segue from my main ViewController to a navigation controller. 我已经从我的主ViewController到导航控制器创建了一个segue。 The segue works fine if I trigger it using a button in my ViewController view, but I can't call that method from my AppDelegate . 如果我使用ViewController视图中的按钮触发它,segue效果很好,但是我无法从AppDelegate调用该方法。

The name of the method(that performs the segue) is -displayLoginView but I can´t find a way to point to the particular instance of my ViewController that is active at launch. 该方法(执行segue)的名称是-displayLoginView但是我找不到指向启动时处于活动状态的ViewController特定实例的方法。

Any ideas? 有任何想法吗?

Your UIApplicationDelegate is not a view controller so it cannot initiate any segues. 您的UIApplicationDelegate不是视图控制器,因此它无法启动任何Segue。

You probably want to call self.window.rootViewController to get the viewcontroller in question but it might be easier to put that code in your viewController 's viewDidAppear or viewWillAppear method instead of the app delegate. 您可能想调用self.window.rootViewController来获取有关viewcontroller的问题,但将代码放入viewControllerviewDidAppearviewWillAppear方法而不是应用程序委托中可能会更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM