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

1 Answer 1

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")
    }
Sign up to request clarification or add additional context in comments.

4 Comments

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
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
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?
Which library did you use for the menu? Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.