我一直在四處搜索大量的stackoverflow並閱讀了許多與代表團有關的不同問題,但是我還沒有能夠解決我的問題。我試圖讓我的stepperAction(它在tableview單元格內)在每次點擊它時改變我的BuyStats類中的標籤。但是到目前爲止,單擊步進器沒有任何作用。我想我需要在BuyStats.viewDidLoad()中設置委託,但我沒有得到它。這對某人來說可能很容易。謝謝你的幫助。Swift代表團 - 在Tableview Cell中使用步進器更新獨立類中的標籤
protocol SetRemainingValue : class {
func setValue(amount: Double)
}
}
//
class BuyStatsCell: UITableViewCell{
weak var setRemaining : SetRemainingValue?
@IBAction func stepperAction(_ sender: UIStepper) {
setRemaining?.setValue(amount: sender.value)
}
//
class BuyStats: UIViewController, SetRemainingValue {
@IBOutlet weak var spendAmount: UILabel!
override func viewDidLoad(){
}
func setValue(amount: Double) {
spendAmount.text = amount
}
}
你在哪裏創建了你的'BuyStatsCell'對象?你需要在'BuyStats'類的某個地方設置'obj.setRemaining = self'。否則,沒有定義「BuyStatsCell」的'delegate'是誰,並且您通過委派傳遞的消息不會生效。要了解更多關於這些協議和代表如何工作,你可以看看[這個答案](http://stackoverflow.com/a/41689281/3687801) – nayem