ios – 在AppDelegate中,主UI UI如何实例化?

ios – 在AppDelegate中,主UI UI如何实例化?,第1张

概述Master-Detail Xcode项目中的默认代码片段 AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // Override point for customization after master-detail Xcode项目中的默认代码片段

AppDelegate.m

- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    // OverrIDe point for customization after application launch. UINavigationController *navigationController = (UINavigationController *)self.window.rootVIEwController;  // *** here ***    MasterVIEwController *controller = (MasterVIEwController *)navigationController.topVIEwController;    controller.managedobjectContext = self.managedobjectContext;    return YES;}

AppDelegate.h

@property (strong,nonatomic) UIWindow *window;

我知道@synthesize只是设置访问器方法,并且没有自动发生初始化.但是如果窗口没有被明确地初始化,那么窗口如何具有非null的RootVIEwController?这只是Xcode在幕后吗?

解决方法 从 my book:

If you choose the Storyboard option as you specify a template,the process works a little differently. The app is given a main storyboard,pointed to by the Info.pList key “Main storyboard file base name” (UIMainStoryboardfile). After UIApplicationMain instantiates the app delegate class,it asks the app delegate for the value of its window property; if that value is nil,the window is created and assigned to the app delegate’s window property. The storyboard’s initial vIEw controller is then instantiated and assigned to the window’s rootVIEwController property,with the result that its vIEw is placed in the window as its root vIEw; the window is then sent the makeKeyAndVisible message. All of that is done behind the scenes by UIApplicationMain,with no visible code whatever. That is why,in a storyboard template,the application:dIDFinishLaunchingWithOptions: implementation is empty.

总结

以上是内存溢出为你收集整理的ios – 在AppDelegate中,主UI UI如何实例化?全部内容,希望文章能够帮你解决ios – 在AppDelegate中,主UI UI如何实例化?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1111788.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存