0
votes

In fact, I was looking for an example of a drop-down button. But unfortunately it turned out to be not fully working, and I do not know well how dynamic constraints and anchors work. Therefore I ask for your help.

'NSGenericException', reason: 'Unable to activate constraint with
anchors and because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.

You can find my source code on Github: https://github.com/Archetapp/Drop-Down-Menu/blob/master/sdafjkbslib/ViewController.swift

I found similar problems and their solution was:

  • Check whether you added the programmatically created view to its parent before activating constraints.

  • Check whether you write constraints activation code inside viewDidLoad () / viewWillAppear (). You should write constraints in the updateViewConstraints or viewWillLayoutSubviews.

  • Check whether you turn off translatesAutoresizingMaskIntoConstraints.

But it did not help me.

1
you need to display dropdown menu right?Ganesh Manickam
@GaneshManickam yes, forgot to write, it is displayed and working, the problem occurs when the controller is closed (when the button is called by the method RemoveFromSuperview)Mikhail Sein

1 Answers

1
votes

For dropdown i mostly prefer this library less number of code and easy to handle

initialize

let dropDown = DropDown()

// The view to which the drop down will appear on
dropDown.anchorView = view // UIView or UIBarButtonItem

// The list of items to display. Can be changed dynamically
dropDown.dataSource = ["Car", "Motorcycle", "Truck"]

Handle selection

// Action triggered on selection
dropDown.selectionAction = { [unowned self] (index: Int, item: String) in
  print("Selected item: \(item) at index: \(index)")
}

Handle show and hide

dropDown.show()
dropDown.hide()

very easy to customize

Hope this will help you