簡體   English   中英

快速從另一個類更改變量的值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM