SlideMenuController未显示

时间:2016-08-29 11:32:46

标签: ios swift

我正在尝试使用Home libraryLogin屏幕上放置左侧菜单,但是在通过Login屏幕后。问题是当我点击main.storyboard屏幕的按钮时,显示的是没有菜单的空白屏幕。

我做了什么:

  • UIViewController我添加了一个Login,其中有一个按钮(这将是我未来的UIViewControllerProve屏幕),我已将其声明为"是初始视图控制器&# 34 ;.我还使用UIViewControllerProve引用了此屏幕。

import UIKit class UIViewControllerProve: UIViewController { @IBAction func btnProve(sender: AnyObject) { createMenuView() } override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } class ContainerViewController: SlideMenuController { override func awakeFromNib() { if let controller = self.storyboard?.instantiateViewControllerWithIdentifier("Main") { self.mainViewController = controller } if let controller = self.storyboard?.instantiateViewControllerWithIdentifier("Left") { self.leftViewController = controller } super.awakeFromNib() } } private func createMenuView() { let storyboard = UIStoryboard(name: "Main", bundle: nil) let mainViewController = storyboard.instantiateViewControllerWithIdentifier("MainViewController") as! MainViewController let leftViewController = storyboard.instantiateViewControllerWithIdentifier("LeftViewController") as! LeftViewController let nvc: UINavigationController = UINavigationController(rootViewController: mainViewController) UINavigationBar.appearance().tintColor = UIColor(hex: "689F38") leftViewController.mainViewController = nvc self.slideMenuController()?.automaticallyAdjustsScrollViewInsets = true let appDelegate = UIApplication.sharedApplication().delegate appDelegate!.window?!.backgroundColor = UIColor(red: 236.0, green: 238.0, blue: 241.0, alpha: 1.0) appDelegate!.window?!.rootViewController = self.slideMenuController() appDelegate!.window?!.makeKeyAndVisible() self.slideMenuController()?.openLeft() } } 上我有以下代码:

AppDelegate.swift
  • createMenuView我已评论过这些功能:applicationLogin

  • 我参考了创作者在GitHub中的例子。

当我点击background-image屏幕上的按钮时,如何显示菜单?我错过了什么吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

首先添加此行Appdelegate

 let storyboard = UIStoryboard(name: "Main", bundle: nil)

     let mainViewController = storyboard.instantiateViewControllerWithIdentifier("MainViewController") as! MainViewController

let leftViewController = storyboard.instantiateViewControllerWithIdentifier("LeftViewController") as! LeftViewController


    let nvc: UINavigationController = UINavigationController(rootViewController: mainViewController)
     leftViewController.welcomescreen = nvc
    let slideMenuController = ExSlideMenuController(mainViewController:nvc, leftMenuViewController: leftViewController)
     slideMenuController.automaticallyAdjustsScrollViewInsets = true
    slideMenuController.delegate = mainViewController2
    self.window?.rootViewController = slideMenuController
    self.window?.makeKeyAndVisible()

然后添加按钮操作后 只有一行

 slideMenuController()?.toggleLeft()

然后打开幻灯片菜单并选择选项。