I am working on an app which requires me to be able to access a variable, tagToIndex
that is in a function within the stub of a a delegate.
The class MyCell
is being used as a custom class for table view cells. In the table view, each cell contains a segmented control. Each individual segmented control has a tag attached to it that corresponds to the cell row that the segmented control is in (tag definition not shown in code).
The segmented controls output an index for the option that is selected (i.e. option 0 corresponds to index of 0, and option 1 corresponds to index of 1) via a delegate (shown below as "stub")
The job of the tagToIndex
dictionary is to take the selected indices of the segmented control and pair them with the tag that corresponds to that segmented control (i.e. if the segmented control in row 5 had an index value of 1, the value would be [5:1].
My question is: How can I read/access the dictionary tagToIndex
in the class MyCell, as well as in other classes? Currently it is "stuck" within the willPressItemAt
function. I have tried using another delegate, but it seems as if I would run into the same problem again, only tagToIndex
would be within a different function
class MyCell: UITableViewCell, YSSegmentedControlDelegate {
var delegate: TagToIndexDelegate?
**//Creating Variable tagToIndex**
var tagToIndex = [0:0,1:0,2:0,3:0,4:0,5:0]
**// Some Logic...**
**//Segmented Control**
let actionButton = YSSegmentedControl(
frame: CGRect.zero,
titles: [
"Yes",
"No"
])
**// Some Layout Stuff**
**//The Stub**
func segmentedControl(_ segmentedControl: YSSegmentedControl, willPressItemAt index: Int) {
**//Modifying Variable tagToIndex **
tagToIndex[actionButton.tag] = index
delegate?.finishPassing(dictionary: tagToIndex)
print(tagToIndex)
}
func segmentedControl(_ segmentedControl: YSSegmentedControl, didPressItemAt index: Int) {
}
}
I need to use the dictionary for an if else statement within another class. The class's name is AnswerViewController
, and it is just a regular UIViewController
Here is a picture of my app so far, just in case you are having trouble imagining it: https://i.stack.imgur.com/ezMUJ.png
Thanks, Nick