I have a uibutton that i want to click and unclick . When i first load the data i set the scroll layout to vertical . I want if i click for the first time the layout of scrolling to be vertical and if i click it again to come back to horizontal and so on . Now what i did it , when i click it for the first time it completely becomes inactive and i can not click on it again . The layout also doesnt change . This is a piece of my code:
let layout = UICollectionViewFlowLayout()
@IBAction func onSelect(_ sender: UIBarButtonItem) {
if !sender.isEnabled {
sender.isEnabled = true
layout.scrollDirection = .horizontal
changeViewBarBtn.title = Constants.barButtonChoice[0]
} else {
sender.isEnabled = false
layout.scrollDirection = .vertical
changeViewBarBtn.title = Constants.barButtonChoice[1]
}
As a point of clarifying , i have a collection view as an outlet within the view controller that i dragged }