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

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

问题描述

我有一个iOS应用程序,我在xCode中创建为基于视图的应用程序。我只有一个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.

我的app delegate.h:

My app delegate.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天全站免登陆