我是新手,最近接触iOS开发,关注this tutorial并尝试通过单 View 应用程序从 Xcode 构建中识别结构。
但我发现一些问题,没有相关的 ViewController.h
被导入 AppDelegate.h,而且我知道整个应用程序的入口是 main.m
调用 AppDelegate.h
,我所有的逻辑代码都在ViewController.h
等
main.m
AppDelegate.h
可能我描述不清楚,我只是想知道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/