![](/img/trans.png)
[英]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.