Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 访问委托存根中的变量_Ios_Swift_Delegation - Fatal编程技术网

Ios 访问委托存根中的变量

Ios 访问委托存根中的变量,ios,swift,delegation,Ios,Swift,Delegation,我有一个变量,tagToIndex,它存在于委托的存根中。看起来是这样的: func segmentedControl(_ segmentedControl: YSSegmentedControl, willPressItemAt index: Int) { tagToIndex[actionButton.tag] = index delegate?.finishPassing(dictionary: tagToIndex) print(tagToIndex) }

我有一个变量,
tagToIndex
,它存在于委托的存根中。看起来是这样的:

 func segmentedControl(_ segmentedControl: YSSegmentedControl, willPressItemAt   index: Int) {
    tagToIndex[actionButton.tag] = index
    delegate?.finishPassing(dictionary: tagToIndex)
    print(tagToIndex)

}

func segmentedControl(_ segmentedControl: YSSegmentedControl, didPressItemAt index: Int) {

}

}
目前,这存在于类
MyCell
中。我希望能够在另一个名为
AnswerViewController
的类中访问它

我尝试使用委托将
tagToIndex
传递给
AnswerViewController
,但据我所知,我只会在AnswerViewController中的另一个存根中使用
tagToIndex

我的问题是:有没有办法从另一个类(
AnswerViewController
)或者甚至在它已经在的类(
MyCell
)中访问
tagToIndex

谢谢,
尼克

如果我理解正确,您的
tagToIndex
存在于
MyCell
AnswerViewController
中,您希望随时随地访问它。如果是这样,为什么不将其作为
sharedInstance
类中的变量?您的问题不清楚,请以更好的方式解释。