我正在通过以下方式设置一个包含多个ViewController的MainViewController:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let pageController = UIPageViewController(
transitionStyle: UIPageViewControllerTransitionStyle.scroll,
navigationOrientation: UIPageViewControllerNavigationOrientation.horizontal,
options: nil
)
let navigationController = MainViewController(rootViewController: pageController)
navigationController.view.backgroundColor = UIColor.white
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let leftView = storyboard.instantiateViewController(withIdentifier: "VC1")
let middleView = storyboard.instantiateViewController(withIdentifier: "VC2")
let rightView = storyboard.instantiateViewController(withIdentifier: "VC3")
navigationController.viewControllerArray = [leftView, middleView, rightView]
self.window!.rootViewController = navigationController
self.window!.makeKeyAndVisible()
return true
}
}
我的MainViewController也有一个浮动按钮。我在情节提要中添加了此功能(请参见下图)。问题在于该按钮未显示。如何显示? 我知道这个问题与我在AppDelegate中添加MainViewController的事实有关,但是我不确定这是如何隐藏按钮的。
答案 0 :(得分:1)
您不是从情节提要中创建MainViewController
实例,而是通过调用其初始化程序来创建它。这意味着将不会加载任何情节提要元素
您需要以下内容:
let navigationController = storyboard.instantiateViewController(withIdentifier: "Main")
navigationController.viewControllers = [pageController]