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
类中的变量?您的问题不清楚,请以更好的方式解释。