TBXark / PinterestSegment

A Pinterest-like segment control with masking animation.
http://tbxark.com/2016/12/08/2016-12-08-Swift-Pinterst/
MIT License
687 stars 56 forks source link

Invoke value change event automatically without any tap on the tabs #19

Closed Travloper closed 3 years ago

Travloper commented 3 years ago

I want to get inside the value change event automatically during the viewWillAppear. There's an API call which indicates which tab should be active. I have achieved to set active tabs by

self.pinterstSegment.setSelectIndex(index: tab ?? 0)

But it doesn't catch up the value change event in -

self.pinterstSegment.valueChange = {index in
            // print("Value change successful")
}

(When i press any tab and then call goes back and forth. The "value change event" get called up automatically) Could you please guide me how i can invoke this value change event without clicking on any of the tabs in first go.

TBXark commented 3 years ago

Because it is judged here that if the index does not change, valueChange will not be used.

https://github.com/TBXark/PinterestSegment/blob/c043d2be59807942abcf70adbf82991c8c197b25/PinterestSegment/PinterestSegment.swift#L169


But you can modify this code to force an update

Before https://github.com/TBXark/PinterestSegment/blob/c043d2be59807942abcf70adbf82991c8c197b25/PinterestSegment/PinterestSegment.swift#L148

After

setSelectIndex(index: index, animated: animated, sendAction: true, forceUpdate: true)