[英]Assign value received from @escaping to instance variable in another class in swift
[英]changing the value of a variable from another class in swift
我创建了一个自定义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()
}
}
....
}
现在,我想在其中添加此自定义细分控件的viewController中更改变量selectedIndex
的值。
我想这是一个如何从另一个类访问/更改变量的问题。
我试图创建一个class func
,该class func
将设置selectedIndex
的值,但是我也无法访问它来访问selectedIndex
变量。
对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.