当我在应用程序委托中将“ HomePageVC”设置为我的根视图控制器时,它只是显示为黑色(保存导航控制器)。 “ HomePageVC”的UI元素是通过情节提要而非编程方式设置的。我确保在画布中正确地将ViewController子类化,并且情节提要/还原ID与子类相同,即“ HomePageVC”
我的应用程序代表-
let firstViewController = HomePageVC()
let navController = UINavigationController(rootViewController: firstViewController)
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = navController
window?.makeKeyAndVisible()
return true
我的HomePageVC
由于某些原因,我使用的任何程序化UI确实会显示在屏幕上,但我使用情节提要放置的UI却没有。
答案 0 :(得分:1)
如果vc在storboard中,则需要从那里加载它,因此请替换
let firstViewController = HomePageVC()
使用
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeId") as! HomePageVC
顺便说一句,您可以将vc根目录嵌入IB中的导航中,并将其设置为初始vc而不是
答案 1 :(得分:-1)
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController : UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "HomePageVC") as HomePageVC
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
return true
}