2017-08-29 249 views
0

我正在使用ENSideMenu Library在Swift中的導航欄中創建菜單。我已經創建了導航欄的左側菜單,但是當我創建右側時。發生的是,當我點擊包含顯示右側菜單的動作的右側按鈕時......將顯示左側菜單。這是我目前的實施。右側菜單在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) 

} 
+0

中發佈的問題,如果您只是將sidenavigation控制器的位置更改爲ENSideMenuPosition.right,然後看它是否來自右側? – 3stud1ant3

+0

@ 3stud1ant3是的,我知道我可以改變菜單的位置。但是,我的問題是當我有兩個菜單,只有一個菜單顯示。無論如何,如果我點擊右邊或左邊的菜單。 – KaelJasper

+0

你可以爲你的右鍵菜單顯示btn動作的代碼嗎? – 3stud1ant3

回答