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). afteruiapplicationmaininstantiates app delegate class, asks app delegate value ofwindowproperty; if value nil, window created , assigned app delegate’swindowproperty. storyboard’s initial view controller instantiated , assigned window’srootviewcontrollerproperty, result view placed in window root view; window sentmakekeyandvisiblemessage. of done behind scenesuiapplicationmain, no visible code whatever. why, in storyboard template,application:didfinishlaunchingwithoptions:implementation empty.
Comments
Post a Comment