[英]changing the value of a variable from another class in swift
I have created a custom UISegment Control 我创建了一个自定义UISegment控件
@IBDesignable class CardsSegmentedControl: UIControl {
private var labels = [UILabel]()
var thumbView = UIView()
var items: [String] = ["Saved Cards", "Add Card"] {
didSet {
setupLabels()
}
}
var selectedIndex : Int = 0 {
didSet {
displayNewSelectedIndex()
}
}
....
}
Now I wish to change the value of the variable selectedIndex
in the viewController where I am adding this custom segment control in. 现在,我想在其中添加此自定义细分控件的viewController中更改变量
selectedIndex
的值。
I guess it is a problem of how to access/change variables from another class. 我想这是一个如何从另一个类访问/更改变量的问题。
I tried to create a class func
which would set the value of the selectedIndex
but I cannot get it to access the selectedIndex
variable either. 我试图创建一个
class func
,该class func
将设置selectedIndex
的值,但是我也无法访问它来访问selectedIndex
变量。
Still pretty new to Swift so please bear with me. 对Swift来说还是很新的,所以请忍受我。
// Inside your ViewController class, create a new instance of your custom class
var cardSegmentedControl = CardSegmentedControl()
// here, change its property value
cardSegmentedControl.selectedIndex = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.