Remove all subviews from a Stack View

0

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)
}
    
asked by anonymous 25.09.2018 / 21:36

1 answer

0

I was wrong since I am adding "subviews" the correct function is to access the values of the "subviews" of my Stack View so I changed my function.

for itemSubView in self.viewPossibleAnswer.subviews{
 itemSubView.removeFromSuperview()
}

I hope this can help.

    
25.09.2018 / 21:36