storyboard 有三個概念是最容易混淆:
storyboard VS xib:
storyboard 注重於多個頁面的層級關係及跳轉
xib 注重於單個頁面的佈局,若多人開發同個專案,xib 比較推薦
先建專案
設定存檔路徑
New Group
New File
選Cocoa Touch Class
p.s: MainVC = Main ViewController
info.plist -> Application Scene Manifest -> Scene Configuration -> Application Session Role -> Item0 ( Default Configuration ) -> 刪掉 Storyboard Name
選擇xib檔
找到 SceneDelegate.swift 下的 scene 函數
修改為此
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
// MARK: Without NavigationController
// let rootVC = MainVC(nibName: String(describing: MainVC.self), bundle: nil)
// MARK: With NavigationController
let rootVC = UINavigationController(rootViewController: MainVC())
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.rootViewController = rootVC //navController
window?.makeKeyAndVisible()
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
}
刪除這兩個檔案
測試:
在MainVC.xib檔下新增一個Lable,拉Outlet到Main.swift檔下
燒到模擬器
這樣就完成 Xcode 的 xib 環境建置了!明天會分享 push 、 present 轉畫面,敬請期待!