ios - In an AppDelegate, how is the main UIWindow instantiated? -
a snippet of default code in master-detail xcode project
appdelegate.m
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { // override point 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;
i aware @synthesize sets accessor methods, , no initialization happens automagically. how window
have non-nil rootviewcontroller
if never explicitly initialized? xcode init'ing behind scenes?
from my book:
if choose storyboard option specify template, process works little differently. app given main storyboard, pointed info.plist key “main storyboard file base name” (
uimainstoryboardfile
). afteruiapplicationmain
instantiates app delegate class, asks app delegate value ofwindow
property; if value nil, window created , assigned app delegate’swindow
property. storyboard’s initial view controller instantiated , assigned window’srootviewcontroller
property, result view placed in window root view; window sentmakekeyandvisible
message. of done behind scenesuiapplicationmain
, no visible code whatever. why, in storyboard template,application:didfinishlaunchingwithoptions:
implementation empty.
Comments
Post a Comment