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

前端之家收集整理的这篇文章主要介绍了ios – 在AppDelegate中,主UI UI如何实例化?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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.

原文链接:https://www.f2er.com/iOS/336636.html

猜你在找的iOS相关文章