1

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

kinghenry14
  • 1,187
  • 1
  • 11
  • 34

1 Answers1

1

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")
    }
Sahil Manchanda
  • 9,812
  • 4
  • 39
  • 89
  • How do I add a specific handler that is different for each menu item? I want to navigate to different views depending on the item they tap – kinghenry14 Jul 20 '17 at 14:21
  • This is the common function for all your menuitems. look at its signature. you are getting the position i.e. which item was clicked. based on position you can get to know which item was clicked. make a switch case and call your item specific handler – Sahil Manchanda Jul 20 '17 at 16:34
  • if I implement code such as harcoded to CGRect.containts(point) will this not work on different size iOS devices? such as 7+ vs 6 vs SE vs iPad? – kinghenry14 Jul 21 '17 at 04:32
  • Which library did you use for the menu? Thanks – DJMacross Aug 04 '17 at 15:58