How do I create a new Swift project without using Storyboards?

后端 未结 13 953
不知归路
不知归路 2020-11-29 15:47

Creating a new project in XCode 6 doesn\'t allow to disable Storyboards. You can only select Swift or Objective-C and to use or not Core Data.

I tried deleting the s

13条回答
  •  悲哀的现实
    2020-11-29 16:19

    Here is a complete swift test example for an UINavigationController

            import UIKit
            @UIApplicationMain
            class KSZAppDelegate: UIResponder, UIApplicationDelegate {    
              var window: UIWindow?
              var testNavigationController: UINavigationController?
    
              func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
                // Override point for customization after application launch.        
                // Working WITHOUT Storyboard
                // see http://randexdev.com/2014/07/uicollectionview/
                // see http://stackoverflow.com/questions/24046898/how-do-i-create-a-new-swift-project-without-using-storyboards
                window = UIWindow(frame: UIScreen.mainScreen().bounds)
                if let win = window {
                  win.opaque = true    
                //you could create the navigation controller in the applicationDidFinishLaunching: method of your application delegate.    
                  var testViewController: UIViewController = UIViewController()
                  testNavigationController = UINavigationController(rootViewController: testViewController)
                  win.rootViewController = testNavigationController
                  win.backgroundColor = UIColor.whiteColor()
                  win.makeKeyAndVisible()
    // see corresponding Obj-C in https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html#//apple_ref/doc/uid/TP40011313-CH2-SW1
            //      - (void)applicationDidFinishLaunching:(UIApplication *)application {
            //    UIViewController *myViewController = [[MyViewController alloc] init];
            //    navigationController = [[UINavigationController alloc]
            //                                initWithRootViewController:myViewController];
            //    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
            //    window.rootViewController = navigationController;
            //    [window makeKeyAndVisible];
                //}
                }
                return true
              }
        }
    

提交回复
热议问题