This is my first post! This is Lee. I will post it like a memo so that I will not forget what I learned in my studies.
It seems that Storyboard is rarely used in practice. I will introduce how to develop by dividing into Xib files without using Storyboard.
First, let's delete the view controller and storyboard after creating the project! !! After deleting, add the file. Be sure to check Also create XIB file before adding a file with cocoa TouchClass. This time, name it sampleViewController. After creating the file, set it in Info.plist. 4th from the bottom of this screen [Delete the Main storyboard file base name with a minus. Next, press the arrow of Application Scene Manifest and it will look like the image. The Storyboard Name of [Item 0] is also deleted with a minus.
This is the end of the setting. From here, it will be created automatically after creating the project We'll write the code in the SceneDelegate.swift file! I don't know what the code here is, so let's remember it like a spell lol
SceneDelegate.swift
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// 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).
guard let scene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: scene)
window?.makeKeyAndVisible()
let sampleVC = sampleViewController()
let rootVC = UINavigationController(rootViewController: sampleVC)
window?.rootViewController = rootVC
}
This will also add a navigation bar! !! In this way, a blank screen is displayed first without any error.
Since the storyboard is gone, we will continue to use XIB for the screen UI. That's how to develop Xib files separately without using Storyboard! !!
Recommended Posts