Side menu handling ios











up vote
0
down vote

favorite












I am playing with 3 Main Classes Please have a look



I have integrated https://github.com/jonkykong/SideMenu



I have one tableview which act as leftViewController



This class is show the list of menu user has



import UIKit

struct SideMenuListItem {
var name:String
var isSelected: Bool
var notificationCount:Int
var viewController:UIViewController
}

protocol SideMenuItemTappedDelegate:class {
func itemTapped(item:SideMenuListItem,index:Int)
}

class SideMenuListVC: UIViewController {

//MARK:- Outlets

@IBOutlet weak var tableView: UITableView!

//MARK:- Var

weak var delegate : SideMenuItemTappedDelegate?

//Please ignore repetition `viewController` this is just for testing
private let menuItems = [SideMenuListItem(name: "Inbox", isSelected: false, notificationCount: 25,viewController:MapVC.viewController()),
SideMenuListItem(name: "Stats", isSelected: false, notificationCount: 0,viewController:PageContentViewController.viewController(pageData:PageData(title: "How to do", desc: "TEST STATS", image: UIImage(named: "Rectangle 2 copy")!))),
SideMenuListItem(name: "Calendar", isSelected: false, notificationCount: 12,viewController:MapVC.viewController()),
SideMenuListItem(name: "Map", isSelected: true, notificationCount: 0,viewController:MapVC.viewController()),
SideMenuListItem(name: "Settings", isSelected: false, notificationCount: 0,viewController:PageContentViewController.viewController(pageData:PageData(title: "How to do", desc: "TEST SETTINGS", image: UIImage(named: "Rectangle 2 copy")!)))]

var getCurrentSelectedItem:SideMenuListItem? {
return menuItems.first{$0.isSelected}
}

...


When User Login I call following class (root view controller) embedded in navigation controller



import UIKit
import SideMenu

class SideMenuVC: UIViewController {

//--------------------------------------------------------------------------------

//MARK:- Memory Managment Methods

//--------------------------------------------------------------------------------

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}


//--------------------------------------------------------------------------------

//MARK:- Custom Methdos

//--------------------------------------------------------------------------------

private func configureSideMenu() {
AppGlobalManager.sharedManager.setupSideMenu()
AppGlobalManager.sharedManager.leftMenuViewController.delegate = self

if let vc = AppGlobalManager.sharedManager.leftMenuViewController.getCurrentSelectedItem?.viewController {
self.addChildVC(vc)
}

}

private func addChildVC (_ vc:UIViewController) {
self.addChild(vc)
self.view.addSubview(vc.view)
vc.view.frame = self.view.bounds
vc.didMove(toParent: self)

}

//--------------------------------------------------------------------------------

//MARK:- ViewLifeCycle Methods

//--------------------------------------------------------------------------------


override func viewDidLoad() {
super.viewDidLoad()

self.configureSideMenu()
}

//--------------------------------------------------------------------------------

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

//--------------------------------------------------------------------------------

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
}



}


And This is AppGlobalManager Which is Shared class



import UIKit
import SideMenu
import Foundation

class AppGlobalManager: NSObject {

static let sharedManager = AppGlobalManager()

lazy var leftMenuViewController = SideMenuListVC.viewController()

public func setupSideMenu () {
let sideMenu = UISideMenuNavigationController(rootViewController: leftMenuViewController)
SideMenuManager.default.menuLeftNavigationController = sideMenu
SideMenuManager.default.menuLeftNavigationController?.isNavigationBarHidden = true
SideMenuManager.default.menuWidth = UIScreen.main.bounds.width
SideMenuManager.default.menuPresentMode = .menuDissolveIn
SideMenuManager.default.menuFadeStatusBar = false

}

}


What I am doing :




  1. On Login set SideMenuVC to root View controller

  2. Setup Side menu controller from AppGlobalManager (shared instance )class


  3. Keep leftMenu Controller as global property


  4. Get Current Selected ViewController and add to Child VC


  5. Setup delegate of Menu list so when user tap on cell call addChildVC


Please suggest









share


























    up vote
    0
    down vote

    favorite












    I am playing with 3 Main Classes Please have a look



    I have integrated https://github.com/jonkykong/SideMenu



    I have one tableview which act as leftViewController



    This class is show the list of menu user has



    import UIKit

    struct SideMenuListItem {
    var name:String
    var isSelected: Bool
    var notificationCount:Int
    var viewController:UIViewController
    }

    protocol SideMenuItemTappedDelegate:class {
    func itemTapped(item:SideMenuListItem,index:Int)
    }

    class SideMenuListVC: UIViewController {

    //MARK:- Outlets

    @IBOutlet weak var tableView: UITableView!

    //MARK:- Var

    weak var delegate : SideMenuItemTappedDelegate?

    //Please ignore repetition `viewController` this is just for testing
    private let menuItems = [SideMenuListItem(name: "Inbox", isSelected: false, notificationCount: 25,viewController:MapVC.viewController()),
    SideMenuListItem(name: "Stats", isSelected: false, notificationCount: 0,viewController:PageContentViewController.viewController(pageData:PageData(title: "How to do", desc: "TEST STATS", image: UIImage(named: "Rectangle 2 copy")!))),
    SideMenuListItem(name: "Calendar", isSelected: false, notificationCount: 12,viewController:MapVC.viewController()),
    SideMenuListItem(name: "Map", isSelected: true, notificationCount: 0,viewController:MapVC.viewController()),
    SideMenuListItem(name: "Settings", isSelected: false, notificationCount: 0,viewController:PageContentViewController.viewController(pageData:PageData(title: "How to do", desc: "TEST SETTINGS", image: UIImage(named: "Rectangle 2 copy")!)))]

    var getCurrentSelectedItem:SideMenuListItem? {
    return menuItems.first{$0.isSelected}
    }

    ...


    When User Login I call following class (root view controller) embedded in navigation controller



    import UIKit
    import SideMenu

    class SideMenuVC: UIViewController {

    //--------------------------------------------------------------------------------

    //MARK:- Memory Managment Methods

    //--------------------------------------------------------------------------------

    override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    }


    //--------------------------------------------------------------------------------

    //MARK:- Custom Methdos

    //--------------------------------------------------------------------------------

    private func configureSideMenu() {
    AppGlobalManager.sharedManager.setupSideMenu()
    AppGlobalManager.sharedManager.leftMenuViewController.delegate = self

    if let vc = AppGlobalManager.sharedManager.leftMenuViewController.getCurrentSelectedItem?.viewController {
    self.addChildVC(vc)
    }

    }

    private func addChildVC (_ vc:UIViewController) {
    self.addChild(vc)
    self.view.addSubview(vc.view)
    vc.view.frame = self.view.bounds
    vc.didMove(toParent: self)

    }

    //--------------------------------------------------------------------------------

    //MARK:- ViewLifeCycle Methods

    //--------------------------------------------------------------------------------


    override func viewDidLoad() {
    super.viewDidLoad()

    self.configureSideMenu()
    }

    //--------------------------------------------------------------------------------

    override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    }

    //--------------------------------------------------------------------------------

    override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    }



    }


    And This is AppGlobalManager Which is Shared class



    import UIKit
    import SideMenu
    import Foundation

    class AppGlobalManager: NSObject {

    static let sharedManager = AppGlobalManager()

    lazy var leftMenuViewController = SideMenuListVC.viewController()

    public func setupSideMenu () {
    let sideMenu = UISideMenuNavigationController(rootViewController: leftMenuViewController)
    SideMenuManager.default.menuLeftNavigationController = sideMenu
    SideMenuManager.default.menuLeftNavigationController?.isNavigationBarHidden = true
    SideMenuManager.default.menuWidth = UIScreen.main.bounds.width
    SideMenuManager.default.menuPresentMode = .menuDissolveIn
    SideMenuManager.default.menuFadeStatusBar = false

    }

    }


    What I am doing :




    1. On Login set SideMenuVC to root View controller

    2. Setup Side menu controller from AppGlobalManager (shared instance )class


    3. Keep leftMenu Controller as global property


    4. Get Current Selected ViewController and add to Child VC


    5. Setup delegate of Menu list so when user tap on cell call addChildVC


    Please suggest









    share
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am playing with 3 Main Classes Please have a look



      I have integrated https://github.com/jonkykong/SideMenu



      I have one tableview which act as leftViewController



      This class is show the list of menu user has



      import UIKit

      struct SideMenuListItem {
      var name:String
      var isSelected: Bool
      var notificationCount:Int
      var viewController:UIViewController
      }

      protocol SideMenuItemTappedDelegate:class {
      func itemTapped(item:SideMenuListItem,index:Int)
      }

      class SideMenuListVC: UIViewController {

      //MARK:- Outlets

      @IBOutlet weak var tableView: UITableView!

      //MARK:- Var

      weak var delegate : SideMenuItemTappedDelegate?

      //Please ignore repetition `viewController` this is just for testing
      private let menuItems = [SideMenuListItem(name: "Inbox", isSelected: false, notificationCount: 25,viewController:MapVC.viewController()),
      SideMenuListItem(name: "Stats", isSelected: false, notificationCount: 0,viewController:PageContentViewController.viewController(pageData:PageData(title: "How to do", desc: "TEST STATS", image: UIImage(named: "Rectangle 2 copy")!))),
      SideMenuListItem(name: "Calendar", isSelected: false, notificationCount: 12,viewController:MapVC.viewController()),
      SideMenuListItem(name: "Map", isSelected: true, notificationCount: 0,viewController:MapVC.viewController()),
      SideMenuListItem(name: "Settings", isSelected: false, notificationCount: 0,viewController:PageContentViewController.viewController(pageData:PageData(title: "How to do", desc: "TEST SETTINGS", image: UIImage(named: "Rectangle 2 copy")!)))]

      var getCurrentSelectedItem:SideMenuListItem? {
      return menuItems.first{$0.isSelected}
      }

      ...


      When User Login I call following class (root view controller) embedded in navigation controller



      import UIKit
      import SideMenu

      class SideMenuVC: UIViewController {

      //--------------------------------------------------------------------------------

      //MARK:- Memory Managment Methods

      //--------------------------------------------------------------------------------

      override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      }


      //--------------------------------------------------------------------------------

      //MARK:- Custom Methdos

      //--------------------------------------------------------------------------------

      private func configureSideMenu() {
      AppGlobalManager.sharedManager.setupSideMenu()
      AppGlobalManager.sharedManager.leftMenuViewController.delegate = self

      if let vc = AppGlobalManager.sharedManager.leftMenuViewController.getCurrentSelectedItem?.viewController {
      self.addChildVC(vc)
      }

      }

      private func addChildVC (_ vc:UIViewController) {
      self.addChild(vc)
      self.view.addSubview(vc.view)
      vc.view.frame = self.view.bounds
      vc.didMove(toParent: self)

      }

      //--------------------------------------------------------------------------------

      //MARK:- ViewLifeCycle Methods

      //--------------------------------------------------------------------------------


      override func viewDidLoad() {
      super.viewDidLoad()

      self.configureSideMenu()
      }

      //--------------------------------------------------------------------------------

      override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(animated)
      }

      //--------------------------------------------------------------------------------

      override func viewDidDisappear(_ animated: Bool) {
      super.viewDidDisappear(animated)
      }



      }


      And This is AppGlobalManager Which is Shared class



      import UIKit
      import SideMenu
      import Foundation

      class AppGlobalManager: NSObject {

      static let sharedManager = AppGlobalManager()

      lazy var leftMenuViewController = SideMenuListVC.viewController()

      public func setupSideMenu () {
      let sideMenu = UISideMenuNavigationController(rootViewController: leftMenuViewController)
      SideMenuManager.default.menuLeftNavigationController = sideMenu
      SideMenuManager.default.menuLeftNavigationController?.isNavigationBarHidden = true
      SideMenuManager.default.menuWidth = UIScreen.main.bounds.width
      SideMenuManager.default.menuPresentMode = .menuDissolveIn
      SideMenuManager.default.menuFadeStatusBar = false

      }

      }


      What I am doing :




      1. On Login set SideMenuVC to root View controller

      2. Setup Side menu controller from AppGlobalManager (shared instance )class


      3. Keep leftMenu Controller as global property


      4. Get Current Selected ViewController and add to Child VC


      5. Setup delegate of Menu list so when user tap on cell call addChildVC


      Please suggest









      share













      I am playing with 3 Main Classes Please have a look



      I have integrated https://github.com/jonkykong/SideMenu



      I have one tableview which act as leftViewController



      This class is show the list of menu user has



      import UIKit

      struct SideMenuListItem {
      var name:String
      var isSelected: Bool
      var notificationCount:Int
      var viewController:UIViewController
      }

      protocol SideMenuItemTappedDelegate:class {
      func itemTapped(item:SideMenuListItem,index:Int)
      }

      class SideMenuListVC: UIViewController {

      //MARK:- Outlets

      @IBOutlet weak var tableView: UITableView!

      //MARK:- Var

      weak var delegate : SideMenuItemTappedDelegate?

      //Please ignore repetition `viewController` this is just for testing
      private let menuItems = [SideMenuListItem(name: "Inbox", isSelected: false, notificationCount: 25,viewController:MapVC.viewController()),
      SideMenuListItem(name: "Stats", isSelected: false, notificationCount: 0,viewController:PageContentViewController.viewController(pageData:PageData(title: "How to do", desc: "TEST STATS", image: UIImage(named: "Rectangle 2 copy")!))),
      SideMenuListItem(name: "Calendar", isSelected: false, notificationCount: 12,viewController:MapVC.viewController()),
      SideMenuListItem(name: "Map", isSelected: true, notificationCount: 0,viewController:MapVC.viewController()),
      SideMenuListItem(name: "Settings", isSelected: false, notificationCount: 0,viewController:PageContentViewController.viewController(pageData:PageData(title: "How to do", desc: "TEST SETTINGS", image: UIImage(named: "Rectangle 2 copy")!)))]

      var getCurrentSelectedItem:SideMenuListItem? {
      return menuItems.first{$0.isSelected}
      }

      ...


      When User Login I call following class (root view controller) embedded in navigation controller



      import UIKit
      import SideMenu

      class SideMenuVC: UIViewController {

      //--------------------------------------------------------------------------------

      //MARK:- Memory Managment Methods

      //--------------------------------------------------------------------------------

      override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      }


      //--------------------------------------------------------------------------------

      //MARK:- Custom Methdos

      //--------------------------------------------------------------------------------

      private func configureSideMenu() {
      AppGlobalManager.sharedManager.setupSideMenu()
      AppGlobalManager.sharedManager.leftMenuViewController.delegate = self

      if let vc = AppGlobalManager.sharedManager.leftMenuViewController.getCurrentSelectedItem?.viewController {
      self.addChildVC(vc)
      }

      }

      private func addChildVC (_ vc:UIViewController) {
      self.addChild(vc)
      self.view.addSubview(vc.view)
      vc.view.frame = self.view.bounds
      vc.didMove(toParent: self)

      }

      //--------------------------------------------------------------------------------

      //MARK:- ViewLifeCycle Methods

      //--------------------------------------------------------------------------------


      override func viewDidLoad() {
      super.viewDidLoad()

      self.configureSideMenu()
      }

      //--------------------------------------------------------------------------------

      override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(animated)
      }

      //--------------------------------------------------------------------------------

      override func viewDidDisappear(_ animated: Bool) {
      super.viewDidDisappear(animated)
      }



      }


      And This is AppGlobalManager Which is Shared class



      import UIKit
      import SideMenu
      import Foundation

      class AppGlobalManager: NSObject {

      static let sharedManager = AppGlobalManager()

      lazy var leftMenuViewController = SideMenuListVC.viewController()

      public func setupSideMenu () {
      let sideMenu = UISideMenuNavigationController(rootViewController: leftMenuViewController)
      SideMenuManager.default.menuLeftNavigationController = sideMenu
      SideMenuManager.default.menuLeftNavigationController?.isNavigationBarHidden = true
      SideMenuManager.default.menuWidth = UIScreen.main.bounds.width
      SideMenuManager.default.menuPresentMode = .menuDissolveIn
      SideMenuManager.default.menuFadeStatusBar = false

      }

      }


      What I am doing :




      1. On Login set SideMenuVC to root View controller

      2. Setup Side menu controller from AppGlobalManager (shared instance )class


      3. Keep leftMenu Controller as global property


      4. Get Current Selected ViewController and add to Child VC


      5. Setup delegate of Menu list so when user tap on cell call addChildVC


      Please suggest







      swift ios





      share












      share










      share



      share










      asked 3 mins ago









      Prashant Tukadiya

      1187




      1187



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209805%2fside-menu-handling-ios%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209805%2fside-menu-handling-ios%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Ellipse (mathématiques)

          Quarter-circle Tiles

          Mont Emei