![](/img/trans.png)
[英]pass data from custom cell(in table which is on ViewController) to the viewcontroller itself Swift3 iOS
[英]How to set/pass value from a custom cell to a viewcontroller in Swift
在我的程序中,在視圖控制器下的UITableView的自定義UITableCell中有一個UISwitch。 我在視圖控制器中創建一個變量,並嘗試記錄所有UISwitch.on的數量。
如何通過UISwitch Action在視圖控制器中設置值?
我在UISwitch Action中編寫了這些代碼。 count是ViewController中的變量
var rootViewController = self.window!.rootViewController as ViewController
rootViewController.count++
println("count:\(rootViewController.count)")
它可以在我的示例程序中使用,但是當我在正式程序中編寫時會出錯。 它始終顯示“線程1:EXC_BREAKPOINT(代碼= EXC_I386_BPT,子代碼= 0x0)”。
我還有另一種方式記錄UISwitch.on的金額嗎?
使用委托可以做到這些。
當開關打開時,視圖控制器中存在的呼叫委托。
在委托方法中,遞增計數變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.