At a certain time in my application I consume an API and add buttons in a Stack View.
The name of my Stack view is "viewPossibleAnswer".
for answer in newListsResponses {
let newButton = UIButton()
newButton.setTitle(answer.sentence, for: .normal)
newButton.setTitleColor(UIColor.white, for: .normal)
self.viewPossibleAnswer.addSubview(newButton)
}
In this way you are inserting the buttons very well but I need to remove all the buttons inside the Stack View at a certain time.
I did the following function to try to remove all buttons from within the Stack View.
for itemSubView in self.viewPossibleAnswer.arrangedSubviews{
self.viewPossibleAnswer.removeArrangedSubview(itemSubView)
}