0

我对iOS相当陌生。我已经能够成功地实现材料按钮和卡片视图,但是侧抽屉控制器如何在情节提要上完成对我来说没有意义。谁能帮忙提供故事板上的示例代码?

寻找一个简单的视图控制器,带有一个可以打开 sidedrawercontroller 的导航按钮。

4

1 回答 1

1

根据我的经验,如果要使用,则必须以编程NavigationDrawerController方式初始化。NavigationDrawerController

但是,您仍然可以通过 Storyboard 布局根视图控制器和侧控制器,并确保在 Interface Builder 中为它们提供正确的 Storyboard ID。

这是我在AppDelegate.swift中的代码

let mainViewController         = instantiateViewControllerWithIdentifier("MainViewController") as! MainViewController        
let sideMenuViewController     = instantiateViewControllerWithIdentifier("SideMenuViewController") as! SideMenuViewController
let navigationController       = NavigationController(rootViewController: mainViewController, leftViewController: sideMenuViewController)        
let navigationDrawerController = NavigationDrawerController(rootViewController: navigationController)

window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = navigationDrawerController
window?.makeKeyAndVisible()

PS 如果你想使用 UINavigationController,只需在 Storyboard 中嵌入带有 UINavigationViewController 的“MainViewController”,并给UINavigationViewController一个 Storyboard ID。最后,将 设置rootViewController为您的UINavigationController实例,而不是MainViewController.

更新Swift3Material 2.0

func instantiateViewControllerWithIdentifier(identifier: String) -> UIViewController {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    return storyboard.instantiateViewController(withIdentifier: identifier)
}

let mainViewController = instantiateViewControllerWithIdentifier(identifier: "MainViewController") as! MainViewController
let sideMenuViewController = instantiateViewControllerWithIdentifier(identifier: "SideMenuViewController") as! SideMenuViewController
let navigationController = NavigationController(rootViewController: mainViewController)
let navigationDrawerViewController = NavigationDrawerController(rootViewController: navigationController, leftViewController: sideMenuViewController, rightViewController: nil)

window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = navigationDrawerViewController
window?.makeKeyAndVisible()
于 2016-07-24T11:34:31.453 回答