KarimEbrahemAbdelaziz / SwiftyMenu

Simple and Elegant Drop down menu for iOS 🔥💥
MIT License
577 stars 56 forks source link

.didSelectItem not being called #32

Closed SamH2022 closed 2 years ago

SamH2022 commented 2 years ago

Hello Karim, First, I would like to thank you for SwiftyMenu, great work !! I have an issue that I can not understand!! I followed your steps to create a simple dropdown list. All SwiftyMenuDelegate methods been called except .didSelectItem Here's my code

@IBOutlet weak var dopdownMenu: SwiftyMenu! //typo in the name :)

 override func viewDidLoad() {
        super.viewDidLoad()

        let arr = ["one", "two", "three"]
        dopdownMenu.items = arr
        /// SwiftyMenu also supports `CallBacks`
        dopdownMenu.didSelectItem = { _, item, index in
            print("Selected \(item) at index: \(index)")
            print(item.displayableValue)
        }

        dopdownMenu.willExpand = {
            print("SwiftyMenu Will Expand!")
        }

        dopdownMenu.didExpand = {
            print("SwiftyMenu Expanded!")
        }

        dopdownMenu.willCollapse = {
            print("SwiftyMenu Will Collapse!")

        }

        dopdownMenu.didCollapse = {
            print("SwiftyMenu Collapsed!")
        }
    }

//extension
//
//  String+Extensions.swift
//  
//
//  Created by Sam on 2022-03-10.
//

import Foundation
import SwiftyMenu

extension String: SwiftyMenuDisplayable {
    public var displayableValue: String {
        return self
    }

    public var retrievableValue: Any {
        return self
    }
}

As you can see, I did create a string extension and set the height constraint on the storyboard. What I'm missing here? I downloaded your sample project and it works just fine. I tried to debug and compare the difference between my simple app and yours but no luck!

Thanks in advance! Regards, Sam

SamH2022 commented 2 years ago

I found out that if a parent view with gesture recognizer UITapGestureRecognizer assigned to it, .didSelectItem won't be called. Fixed it by adding: tapGesture.cancelsTouchesInView = false

Thanks!