我使用引用 https://github.com/evnaz/ENSwiftSideMenu 为所有主视图 Controller 创建了通用的侧边菜单
现在的问题是我已经从 Storyboard创建了侧边菜单 View Controller 而不是使用代码本身,它不会在侧边菜单上显示任何内容。
理想情况下,它必须显示从 Storyboard设计的页面。
实际上只有 TableViewController 可以与这个例子一起工作。我需要使用 UIViewController。
有人知道吗?
最佳答案
查看最新版本,几周前我恰好添加了该功能:您现在可以使用 UIViewController,无需使用 UITableViewController。
但除此之外,如果没有更多信息,我无法判断为什么它没有出现。 我在几个应用程序中使用它并且工作正常。 我有一个 UINavigationController,它使用 ENSideMenuNavigationController 的一个子类,以及一个用于菜单本身的 UIViewController。
就是这样,基本上:
class MainNavigationController: ENSideMenuNavigationController, ENSideMenuDelegate {
override func viewDidLoad() {
super.viewDidLoad()
var mainMenuViewController: MainMenuViewController = storyboard?.instantiateViewControllerWithIdentifier("MainMenuViewController") as! MainMenuViewController
mainMenuViewController.navController = self
sideMenu = ENSideMenu(sourceView: self.view, menuViewController: mainMenuViewController, menuPosition:.Right)
//sideMenu?.delegate = self //optional
sideMenu?.menuWidth = 240.0 // optional, default is 160
sideMenu?.bouncingEnabled = false
sideMenu?.animationDuration = 0.2
// make navigation bar showing over side menu
view.bringSubviewToFront(navigationBar)
}
// MARK: - ENSideMenu Delegate
func sideMenuWillOpen() {
println("sideMenuWillOpen")
}
func sideMenuWillClose() {
println("sideMenuWillClose")
}
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
super.didRotateFromInterfaceOrientation( fromInterfaceOrientation )
sideMenu?.updateFrame()
}
然后我有菜单 View 本身,也在 Storyboard 中,它是一个 UIViewController。这是一个片段:
class ERAMainMenuViewController: UIViewController {
weak var navController: ERAMainNavigationController?
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var exitButton: UIButton!
@IBOutlet weak var headImage: UIImageView!
let kInset:CGFloat = 64.0
override func viewDidLoad() {
super.viewDidLoad()
// Customize apperance of table view
tableView.contentInset = UIEdgeInsetsMake(kInset, 0, 0, 0) //
tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
tableView.backgroundColor = ERAssistantTheme.sideMenuItemBackgroundColor
tableView.scrollsToTop = false
// Preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = true
// tableView.selectRowAtIndexPath(NSIndexPath(forRow: selectedMenuItem, inSection: 0), animated: false, scrollPosition: .Middle)
}
}
关于ios - 使用 swift 的侧边菜单 - 引用 https ://github. com/evnaz/ENSwiftSideMenu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30660656/