Last active
September 6, 2018 10:04
-
-
Save ishaq/7749853 to your computer and use it in GitHub Desktop.
iOS: load main interface programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
UIStoryboard *mainStoryboard = nil; | |
BOOL showLogin = NO; | |
if(showLogin == NO) | |
{ | |
// mainStoryboard method looks like: | |
// return [UIStoryboard storyboardWithName:@"Main" bundle:nil]; | |
mainStoryboard = [UIStoryboard mainStoryboard]; | |
} | |
else | |
{ | |
mainStoryboard = [UIStoryboard loginStoryboard]; | |
} | |
UIViewController *rootController = [mainStoryboard instantiateInitialViewController]; | |
NSAssert(rootController, @"no user interface, what is this? a web service??"); | |
self.window.rootViewController = rootController; | |
[self.window makeKeyAndVisible]; | |
return YES; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
self.window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
var mainStoryboard: UIStoryboard? = nil | |
let showTutorial = true | |
if(showTutorial) { | |
mainStoryboard = UIStoryboard.tutorialStoryboard() | |
} | |
else { | |
// mainStoryboard method looks like: | |
// return UIStoryboard(name: "Main", bundle: nil) | |
mainStoryboard = UIStoryboard.mainStoryboard() | |
} | |
let rootController = mainStoryboard!.instantiateInitialViewController() | |
assert(rootController != nil, "no user interface, must be the D day") | |
self.window?.rootViewController = rootController | |
self.window?.makeKeyAndVisible() | |
return true | |
} |
Note that as of Swift 4 that UIScreen.mainScreen().bounds
(line 2) has been renamed to UIScreen.main.bounds
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for this)