ios - AppDelegate 如何调用 ViewController.h

标签 ios xcode

我是新手,最近接触iOS开发,关注this tutorial并尝试通过单 View 应用程序从 Xcode 构建中识别结构。

但我发现一些问题,没有相关的 ViewController.h 被导入 AppDelegate.h,而且我知道整个应用程序的入口是 main.m 调用 AppDelegate.h,我所有的逻辑代码都在ViewController.h

ma​​in.m

enter image description here

AppDelegate.h

enter image description here

可能我描述不清楚,我只是想知道AppDelegate如何调用ViewController

最佳答案

如果您不使用主 Storyboard ,那么您必须教会 AppDelegate 如何调用您的 ViewController。这是如何执行此操作的快速 Swift 代码:

var window: UIWindow? = UIWindow(frame: UIScreen.mainScreen().bounds)

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    self.window!.rootViewController = ViewController()
    self.window!.makeKeyAndVisible() // this will take care of everything

    return true
}

objective-C :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = [ViewController new];
    [self.window makeKeyAndVisible];

    return YES;
}

关于ios - AppDelegate 如何调用 ViewController.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33665646/

相关文章:

ios - 如何正确设置背景图像

iphone - 如何在 iPhone 构建阶段将文件复制到库或文档目录?

ios - 将本地 CSS 添加到域在线 UIWebView

ios - swift 4.0 : Overriding 'prepare' must be as available as declaration it overrides

html - 将多行 HTML 解析加载到一个 UITextField 中

c++ - 如何将 C++ 库导入 Xcode Objective C 项目?

xcode - 在 NSUserDefaults 中存储字典导致 EXC_BAD_ACCESS

ios - 如何忽略多点触控序列中的某些 UITouch 点

ios - 如何使用 URLSession (Swift 4.2) 触发两 (2) 个 HTTP POST 请求?

ios - 如何使用 SpriteKit 使球仅垂直而不是水平弹跳?