[英]How to set/pass value from a custom cell to a viewcontroller in Swift
In my program, there is a UISwitch in the custom UITableCell of a UITableView under a view controller. 在我的程序中,在视图控制器下的UITableView的自定义UITableCell中有一个UISwitch。 I create a variable in the view controller and try to record the amount of all UISwitch.on.
我在视图控制器中创建一个变量,并尝试记录所有UISwitch.on的数量。
How do I set value in the view controller from the UISwitch Action ? 如何通过UISwitch Action在视图控制器中设置值?
I wrote these code in UISwitch Action. 我在UISwitch Action中编写了这些代码。 count is the variable in the ViewController
count是ViewController中的变量
var rootViewController = self.window!.rootViewController as ViewController
rootViewController.count++
println("count:\(rootViewController.count)")
It works in my sample program, but it has error when I wrote in my formal program. 它可以在我的示例程序中使用,但是当我在正式程序中编写时会出错。 It always shows "Thread 1: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)".
它始终显示“线程1:EXC_BREAKPOINT(代码= EXC_I386_BPT,子代码= 0x0)”。
Do I have another way to record the amount of UISwitch.on ?? 我还有另一种方式记录UISwitch.on的金额吗?
using delegate you can do these . 使用委托可以做到这些。
when switch is ON call delegate that is present in view controller. 当开关打开时,视图控制器中存在的呼叫委托。
In delegate method increment count variable. 在委托方法中,递增计数变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.