如何让工程不使用storyboard和scene


删除info.plist里面的Application Scene mainifest
删除SceneDelegate.swift
删除AppDelegate.swift里面的这两个方法

 func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {

然后在appDelegate,swift里面添加

class AppDelegate: UIResponder, UIApplicationDelegate {var window: UIWindow" />//添加windowfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// Override point for customization after application launch.window = UIWindow(frame: UIScreen.main.bounds)// 设置根视图控制器var VC = UIViewController()VC.view.backgroundColor = UIColor.bluelet rootViewController = VC// 替换为你的视图控制器window?.rootViewController = rootViewControllerwindow?.makeKeyAndVisible()//让window可以被看见return true}}

当点击一个button时显示出下一个ViewController


点击注册后跳转到

左上角自动会有返回的按钮
可以直接在IB界面在添加了VavigationViewController的ViewController里面的button,直接拉线到另一个VC就可以实现这个功能

首先需要将loginViewController包含进一个navigationViewController里面
创建登录button的行为 为

self.navigationController" />.pushViewController(registerVC, animated: true)//registerVC为需要显示出来的VC