I have a tableview which contains multiple custom segmented controls, it looks like this:
https://i.stack.imgur.com/ezMUJ.png
I want to keep track of the status of the segmented control in each row via a dictionary (where the key would be index of the row that the segmented control is in and the value would be the index of the segmented control itself) i.e. if there were 3 rows whose segmented control values were yes, no, yes the dictionary would be [0:1, 1:0, 2:1]
The problem is that the segmented control can only send/receive information via a delegate or callback, so whenever I want to determine the index of the segmented control I have to do it within the delegate function like this:
func segmentedControl(_ segmentedControl: YSSegmentedControl, willPressItemAt index: Int) {
print(index)
}
I have seen the post keeping track of multiple uibutton states in uitableview swift 3, but since custom segmented controls do not "fire" like a button does I cannot think of a way to apply this.
I believe I could fix the problem if I were able to access index
outside of the delegate function, but I can't really figure out how to do that.
Please keep in mind that this is technically a custom UIControl that does not carry any of the same capabilities as a standard UISegmentedControl, so I cannot simply add an action the way I would with a UISegmentedControl (at least I don't think so)
Any help appreciated,
Thanks