iosswift3cosmicmindmaterial-swift

Adding Click Handler to Navigation Drawer MenuItem MaterialSwift


In the image below I have a navigation drawer successfully working and implemented with cosmic mind material swift library.

I am trying to figure out how to add a handler for touch events on any of the menu items, as i cant directly just chain the addTarget method to a single menu item in the array of [MenuItem]s:

let normalMenuItems:[MenuItem] = [
    MenuItem(title: "My Teeups", icon: UIImage.teeup!, selected: true),
    MenuItem(title: "Discover", icon: UIImage.discover!),
    MenuItem(title: "Contacts", icon: UIImage.contacts!),
    .divider,
     MenuItem(title: "Research", icon: UIImage.send!).addTarget(self, action: #selector(goToContacts), for: .touchUpInside),.divider,
    MenuItem(title: "Settings", icon: UIImage.settings!),
    MenuItem(title: "Help", icon: UIImage.help!),
    MenuItem(title: "Send Feedback", icon: UIImage.feedback!)
]

Willing to remove if this is a duplicate, just really don't know what to google for this problem and haven't come across anything to help.

enter image description here


Solution

  • You need to set NavigationDrawerControllerDelegate where you have extend NavigationDrawerController then in the below method you will when user tap on any of the item

    func navigationDrawerController(navigationDrawerController: NavigationDrawerController, didTapAt point: CGPoint, position: NavigationDrawerPosition) {
            print("navigationDrawerController didTapAt: ", point, "with position:", .left == position ? "Left" : "Right")
        }