本文介绍了如何在Swift 3中导航至不同的故事板以及侧面菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用第三方控件命名为 MMDrawerController 的菜单,并使用多个Storyboards处理UI.让我指出我的菜单如下: Sidemenu图片

I am using third party control for sidemenu named : MMDrawerController, and m handling UI using multiple storyboards.let me come to the point my sidemenu looks like this : Sidemenu Image

试图实现:

1)当我单击父项"时,应显示"main.storyboard".

1)When I click on the Parent, "main.storyboard" should be displayed.

2)当我单击管理"时,应显示"management.storyboard".

2)When I click on the Management, "management.storyboard" should be displayed.

应该在所有情节提要文件中显示相同的侧面菜单.

我已经尝试了一些代码,但是没有在"management.storyboard"上获得补充菜单:(

I have tried some code by my own but m not getting the sidemenu on "management.storyboard" :(

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

    switch(indexPath.row)
    {
    case 4:
        let mainstoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        var welview = mainstoryboard.instantiateViewController(withIdentifier: "WelcomeParentViewController") as! WelcomeParentViewController
        var welnav = UINavigationController(rootViewController: welview)
        var appdel : AppDelegate = UIApplication.shared.delegate as! AppDelegate

        appdel.centerContainer!.centerViewController = welnav
        appdel.centerContainer!.toggle(MMDrawerSide.left, animated: true, completion: nil)
        break
    case 5:
        let mainstoryboard : UIStoryboard = UIStoryboard(name: "Management-Storyboard", bundle: nil)
        var welview = mainstoryboard.instantiateViewController(withIdentifier: "ReportsViewController") as! ReportsViewController
        var welnav = UINavigationController(rootViewController: welview)
        var appdel : AppDelegate = UIApplication.shared.delegate as! AppDelegate

        appdel.centerContainer!.centerViewController = welnav
        appdel.centerContainer!.toggle(MMDrawerSide.left, animated: true, completion: nil)
        break
    default :
        break


    }

我希望所有情节提要文件中使用相同的补充菜单.

如何完成上述功能.请帮助.谢谢.

how to accomplish the above feature.Please Help.Thank you in advance.

appdelegate.swift中的MMDrawerController代码

import UIKit
import GoogleMaps

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var centerContainer : MMDrawerController?



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    if isUserLoggedIn()
    {
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.gotoMainvc()
    }
    else
    {
        let rootViewController = self.window!.rootViewController
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let setViewController = mainStoryboard.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
        rootViewController?.navigationController?.popToViewController(setViewController, animated: false)
    }
    return true
}

func isUserLoggedIn() -> Bool{
    if let accessToken = UserDefaults.standard.object(forKey: "access_token") as? String
    {
        if (accessToken.characters.count) > 0{
            return true
        } else {
            return false
        }

    }
    else {
        return false
    }
}
func gotoMainvc()
{

    var rootviewcontroller = self.window?.rootViewController

    if(UIDevice.current.userInterfaceIdiom == .phone)
    {

    let mainstoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

        var centerviewcontroller = mainstoryboard.instantiateViewController(withIdentifier: "WelcomeParentViewController") as! WelcomeParentViewController

        var leftsideviewcontroller = mainstoryboard.instantiateViewController(withIdentifier: "LeftSideMenuViewController") as! LeftSideMenuViewController
        let leftsidenav = UINavigationController(rootViewController: leftsideviewcontroller)
        let centernav = UINavigationController(rootViewController: centerviewcontroller)
        centerContainer = MMDrawerController(center: centernav, leftDrawerViewController: leftsidenav)

        centerContainer?.openDrawerGestureModeMask = MMOpenDrawerGestureMode.panningCenterView
        centerContainer?.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.panningCenterView

        window?.rootViewController = centerContainer
        window?.makeKeyAndVisible()
    }
    else{

        let mainstoryboard2 : UIStoryboard = UIStoryboard(name: "Storyboard-iPad", bundle: nil)
        var centerviewcontroller = mainstoryboard2.instantiateViewController(withIdentifier: "WelcomeParentViewController") as! WelcomeParentViewController

        var leftsideviewcontroller = mainstoryboard2.instantiateViewController(withIdentifier: "LeftSideMenuViewController") as! LeftSideMenuViewController
        let leftsidenav = UINavigationController(rootViewController: leftsideviewcontroller)
        let centernav = UINavigationController(rootViewController: centerviewcontroller)
        centerContainer = MMDrawerController(center: centernav, leftDrawerViewController: leftsidenav)

        centerContainer?.openDrawerGestureModeMask = MMOpenDrawerGestureMode.panningCenterView
        centerContainer?.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.panningCenterView

        window?.rootViewController = centerContainer
        window?.makeKeyAndVisible()
    }

}


//MARK: sharedDelegate

 func sharedDelegate() -> AppDelegate

{
    return UIApplication.shared.delegate as! AppDelegate
}


 }

推荐答案

这是其他情节提要的代码开放端

here is code open side from other storyboard

 @IBAction func menutapped(_ sender: Any) {

        var appdelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
        appdelegate.centerContainer?.toggle(MMDrawerSide.left, animated: true, completion: nil)


    }

这篇关于如何在Swift 3中导航至不同的故事板以及侧面菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:29