我使用引用https://github.com/evnaz/ENSwiftSideMenu
为所有主视图控制器创建了常用的sidemenu现在问题是我从故事板创建了sidemenu视图控制器而不是使用代码本身,它不会在侧面菜单上显示任何内容。
理想情况下,它必须显示故事板设计的页面。
实际上只有TableViewController才能使用这个例子。我需要使用UIViewController。
有人对此有所了解吗?
答案 0 :(得分:2)
查看最新版本,几周前我添加了精确的功能:您现在可以使用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()
}
}
然后我有了菜单视图本身,也在故事板中,这是一个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)
}
}