我将jonkykong/SideMenu与swift结合使用,并通过编程方式创建菜单,而改为使用硬编码菜单。
我要添加菜单:
SideMenuTableViewController.swift
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if let menu = MyMethod.getMenu() {
for (index, value) in menu.enumerated() {
//All the logic to create the view with the label
let tap = UITapGestureRecognizer(target: self,
action: #selector (self.selectMenuItem (_:)))
subItem.addGestureRecognizer(tap)
subItem.addSubview(subLabel)
container.addSubview(subItem)
}
}
return container
}
@objc public func selectMenuItem(_ sender: AnyObject) {
let value = sender.view!.customValue
switch value {
case "item1":
let vc = instantiateViewController(identifier: "mainViewController", type: MainViewController.self)
displayVC(viewController: vc)
case "item2":
let vc = instantiateViewController(identifier: "secondVC", type: SecondViewController.self)
displayVC(viewController: vc)
default:
print("")
}
}
public func displayVC<T: UIViewController>(viewController:T){
let backItem = UIBarButtonItem()
backItem.title = ""
if(self.navigationController?.navigationBar.barTintColor == UIColor.white){
backItem.tintColor = UIColor.black
}
navigationItem.backBarButtonItem = backItem
self.navigationController?.navigationItem.backBarButtonItem = backItem
self.navigationController?.pushViewController(viewController, animated: true)
}
但是每次,我都要求在控制台中获得侧面菜单:
用于开始/结束外观转换的不平衡呼叫
并且没有呼叫viewDidLoad
viewDidAppear
或viewWillAppear
。
存在一种解决方法?