I’m new to xcode and ios development. I’m learning using Brad Larson online courses. Now, he doesn’t use storyboard to create interface. In his delegate file, he’s using code for loading the rootViewController.
Now, when I create a new one page ios project, its seems like it’s not the XYZAppDelegate that is responsible for loading the controller.
I know that in the mainstoryboard.storyboard file, my XYZViewController appears in there. I’m just wondering why it’s not the XYZAppDelegate that is in charge of loading the viewController ?
In the appDelegate, there is nothing in the didFinishLaunchingWithOptions method but the program still loads?
However, the main.m file indicates that XYZAppDelegate is the delegateClassName.
Finally, my question is who’s in charge in that case for loading the XYZViewController if it’s not the AppDelegate ?
These are the default xcode generated files
main.m
return UIApplicationMain(argc, argv, nil, NSStringFromClass([XYZAppDelegate class]));
XYZAppDelegate
#import "XYZAppDelegate.h"
@implementation XYZAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
The answer lies in your Info.plist file. If you look, you’ll see two keys called
Main storyboard file base nameandMain storyboard file base name (iPad)for which the values should be the name of your storyboard files for the respective devices. If these keys are present at launch, the OS will automatically load the storyboard file and insert the first view controller from the storyboard into the app’s window. Docs here for the Info.plist key explanations (the raw key is calledUIMainStoryboardFile).