我正在尝试使用Home
library在Login
屏幕上放置左侧菜单,但是在通过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
我已评论过这些功能:application
和Login
。
我参考了创作者在GitHub中的例子。
当我点击background-image
屏幕上的按钮时,如何显示菜单?我错过了什么吗?
提前致谢!
答案 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()
然后打开幻灯片菜单并选择选项。