First of all, I decided to make my project with only UIKit. So I deleted 'Main' storyboard, Info.plist->Storyboard name, and Main storyboard file base name->Main. And I edited SceneDelegate.
So now I can display the single viewControllers, but when I try to set 'UITabBarController' to rootViewController, It cause this error(title). I tried to make UITabBarController in ViewController, UITabBarController in SceneDelegate and some more.
// BackgroundViewController for the rootViewController
import UIKit
class BackgroundViewController: UIViewController {
let backgroundTabBarController = UITabBarController()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
createTabBar()
}
}
extension BackgroundViewController {
private func createTabBar() {
view.backgroundColor = .white
view.addSubview(backgroundTabBarController.view)
let firstViewController = BookSearchViewController()
let secondViewController = MainViewController()
let thirdViewController = UserStatusViewController()
let lastViewController = OrderViewController()
firstViewController.tabBarItem = UITabBarItem(title: "Search", image: UIImage(systemName: "magnifyingglass.circle.fill"), selectedImage: UIImage(systemName: "magnifyingglass.circle"))
secondViewController.tabBarItem = UITabBarItem(title: "Main", image: UIImage(systemName: "house.fill"), selectedImage: UIImage(systemName: "house"))
thirdViewController.tabBarItem = UITabBarItem(title: "My", image: UIImage(systemName: "person.fill"), selectedImage: UIImage(systemName: "person"))
lastViewController.tabBarItem = UITabBarItem(title: "Order", image: UIImage(systemName: "menucard.fill"), selectedImage: UIImage(systemName: "menucard"))
backgroundTabBarController.viewControllers = [firstViewController, secondViewController, thirdViewController, lastViewController]
backgroundTabBarController.selectedViewController = secondViewController
}
}
// SceneDelegate
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.rootViewController = BackgroundViewController()
window?.makeKeyAndVisible()
}
}
// Error code
Thread 1: "Could not find a storyboard named 'Main' in bundle NSBundle </Users/[MyDesktopName]/Library/Developer/CoreSimulator/Devices/[ApplicationName]/data/Containers/Bundle/Application/[ApplicationName]/BTY.app> (loaded)"
But anyone of this solve the problem. How can I make UITabBarController to rootViewController?
- Make UITabBarController in SceneDelegate
- Make new UIViewController that have UITabBarController and set to rootViewController
- Set ViewControllers with 'UINavigationController(rootViewController:)'
- Present UITabBarController from other viewController