KarimEbrahemAbdelaziz / SwiftyMenu

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

Error when initializing from code #12

Closed gintechsystems closed 3 years ago

gintechsystems commented 4 years ago

Hello,

I have implemented your library using CocoaPods using Xcode 11.4. I am testing on the simulator with iOS 13.4.

I am trying to use your library from code without storyboard at all but it doesn't seem to be working. I am not sure if it is because I am trying to add the menu to a table view cell, but no matter what I do I get a white empty box on the UI side of things and when I am debugging I always see this:

expression produced error: error: /var/folders/1w/ltx7q76130s12wkrq5_tjdxm0000gp/T/expr56-31d3d2..swift:1:88: error: 'SwiftyMenuDisplayable' is not a member type of 'SwiftyMenu'
Swift._DebuggerSupport.stringForPrintObject(Swift.UnsafePointer<Swift.Array<SwiftyMenu.SwiftyMenuDisplayable>>(bitPattern: 0x1090356e0)!.pointee)
                                                                            ~~~~~~~~~~ ^

SwiftyMenu.SwiftyMenu:1:20: note: 'SwiftyMenu' declared here
final public class SwiftyMenu : UIView {

Clicking any menu crashes the application:

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file Pods/SwiftyMenu/SwiftyMenu/Classes/SwiftyMenu.swift, line 470
2020-03-30 11:01:34.684213-0400 ARC Bookshelf[22331:3996509] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file Pods/SwiftyMenu/SwiftyMenu/Classes/SwiftyMenu.swift, line 470

Some of my code on how I am implementing the menu:

class DropdownMenuCellView: MenuCellView, SwiftyMenuDelegate {

    var dropdownMenu: SwiftyMenu?
    var icon: UIImageView?

    private let alphaNormal: CGFloat = 0.0
    private let alphaSelected: CGFloat = 1.0

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        dropdownMenu = SwiftyMenu(frame: CGRect(x: 10.0, y: 0.0, width: self.frame.width - 10.0, height: 30.0))
        dropdownMenu?.delegate = self

        dropdownMenu?.isMultiSelect = false
        //dropdownMenu?.scrollingEnabled = false

        dropdownMenu?.rowBackgroundColor = .menuBackground

        dropdownMenu?.cornerRadius = 0.0

        self.addSubview(dropdownMenu!)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    func swiftyMenu(_ swiftyMenu: SwiftyMenu, didSelectItem item: SwiftyMenuDisplayable, atIndex index: Int) {
        // TODO
    }

}

At quick glance I believe this is related to it being implemented through CocoaPods, since it seems to act as if the module is missing. I am using !use_frameworks in my Podfile. I am not sure if your library does not work in that scenario.

KarimEbrahemAbdelaziz commented 3 years ago

Hi @gintechsystems ,

Thank you for reporting this issue. I will start working on this ASAP.

KarimEbrahemAbdelaziz commented 3 years ago

The coming version I'll provide an example for this use case. Thanks @gintechsystems :)