Search code examples
iosswift3uiscrollviewreloaddata

Reloading contents of scroll view


Is there any way to reload data inside scroll view? I have 5 buttons on scroll view on tap on second I want to reload first button to normal state is it possible?Actually I have table view on which i have 2 rows. Table view cell have a scroll view and on that scroll view I am adding buttons for horizontal scroll I know table reloads but my buttons are on scroll view so I am stuck. Can someone help?


Solution

  • To update several buttons you could do something like this...

    First create an array of the buttons...

    let buttons = [button1, button2, button3, button4, ...]
    

    Now in your target action...

    func buttonTapped(button: UIButton) {
        // filter buttons to get the ones not tapped
        buttons.filter { $0 != button }
        // set them all to be deselected
               .forEach { $0.isSelected = false }
    }
    

    Or something like this.

    It really depends on how you are creating them etc but this would be a very simple approach to it without knowing more about your specific case.