如何从我的 appDelegate 访问我的 viewController?IOS [英] How do I access my viewController from my appDelegate? iOS

查看:20
本文介绍了如何从我的 appDelegate 访问我的 viewController?IOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 xCode 中创建为基于视图的应用程序"的 iOS 应用程序.我只有一个 viewController,但它会自动显示,而且我看不到任何代码将它与我的 appDelegate 联系起来.我需要将数据从我的 appDelegate 传递到我的 viewController,但不知道如何实现.

I have an iOS app I created as a "view-based app" in xCode. I have only one viewController, but it is displayed automatically, and I see no code that ties it to my appDelegate. I need to pass data from my appDelegate to my viewController, but don't know how to pull that off.

我的应用委托.h:

#import <UIKit/UIKit.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) NSDictionary *queryStrings;

@end

此外,appDidFinishLoadingWithOptions:

Also, appDidFinishLoadingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [[JMC sharedInstance] configureJiraConnect:@"https://cmsmech.atlassian.net/"           projectKey:@"WTUPLOAD" apiKey:@"7fc060e1-a795-4135-89c6-a7e8e64c4b13"];

    if ([launchOptions objectForKey:UIApplicationLaunchOptionsURLKey] != nil) {
        NSURL *url = [launchOptions objectForKey: UIApplicationLaunchOptionsURLKey];
        NSLog(@"url received: %@", url);
        NSLog(@"query string: %@", [url query]);
        NSLog(@"host: %@", [url host]);
        NSLog(@"url path: %@", [url path]);
        queryStrings = [self parseQueryString:[url query]];
        NSLog(@"query dictionary: %@", queryStrings);
    }
    else {
        queryStrings = [self parseQueryString:@"wtID=nil"];
    }

    return YES;
}

推荐答案

您可以通过以下方式访问:

You can access it with:

MyViewController* mainController = (MyViewController*)  self.window.rootViewController;

如果您将视图嵌套在 tabviewcontroller 或导航控制器后面,它将返回给您,您需要访问其中的视图控制器

If you are nesting your view behind a tabviewcontroller or navigation controller it will return that to you and you will need to access your view controller inside of it

这篇关于如何从我的 appDelegate 访问我的 viewController?IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆