在Swift中单击右侧菜单时,左侧菜单打开

时间:2017-08-29 02:44:25

标签: swift uinavigationbar xcode8 navigationbar

我使用ENSideMenu Library在Swift的导航栏中创建菜单。我已经创建了导航栏的左侧菜单,但是当我创建右侧时。当我点击包含显示正确菜单的动作的右侧按钮时,会发生这样的情况......而是显示左侧菜单。这是我目前的实施方式。

RightSideNavigationController

override func viewDidLoad() {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let menu = storyboard.instantiateViewController(withIdentifier: "RightMenuTableViewController") as! RightMenuTableViewController

    sideMenu = ENSideMenu(sourceView: self.view, menuViewController: menu, menuPosition: ENSideMenuPosition.right)
    sideMenu?.menuWidth = 200
    view.bringSubview(toFront: navigationBar)
}

RightMenuTableViewController

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    var destView: UIViewController!
    if indexPath.row == 0 {
        destView = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
    } else {
          destView = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController

   }
   sideMenuController()?.setContentViewController(destView)

}

SideNavigationController

override func viewDidLoad() {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let menu = storyboard.instantiateViewController(withIdentifier: "MenuTableViewController") as! MenuTableViewController
    sideMenu = ENSideMenu(sourceView: self.view, menuViewController: menu, menuPosition: ENSideMenuPosition.left)
    sideMenu?.menuWidth = 200
    view.bringSubview(toFront: navigationBar)
}

MenuTableViewController

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    var destinationViewController: UIViewController!



    if indexPath.section == 0{
        if indexPath.row == 0 {
            destinationViewController = storyboard.instantiateViewController(withIdentifier: "TopViewController") as! TopViewController
        } else if indexPath.row == 1 {
              destinationViewController = storyboard.instantiateViewController(withIdentifier: "MemberListViewController") as! MemberListViewController
        }
     }else {
         if indexPath.row == 0 {
             destinationViewController = storyboard.instantiateViewController(withIdentifier: "MemberRegisterViewController") as! MemberRegisterViewController

        } else if indexPath.row == 3 {
              destinationViewController = storyboard.instantiateViewController(withIdentifier: "UserRegistrationViewController") as! UserRegistrationViewController
        }

    }
    sideMenuController()?.setContentViewController(destinationViewController)

}

1 个答案:

答案 0 :(得分:0)

ENSideMenu库目前不支持在同一页面中使用该库的2个菜单。这是根据https://logging.apache.org/log4net/release/manual/configuration.html

中发布的问题