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在幕后吗?
解决方法
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
). AfterUIApplicationMain
instantiates the app delegate class,it asks the app delegate for the value of itswindow
property; if that value is nil,the window is created and assigned to the app delegate’swindow
property. The storyboard’s initial view controller is then instantiated and assigned to the window’srootViewController
property,with the result that its view is placed in the window as its root view; the window is then sent themakeKeyAndVisible
message. All of that is done behind the scenes byUIApplicationMain
,with no visible code whatever. That is why,in a storyboard template,theapplication:didFinishLaunchingWithOptions:
implementation is empty.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。