简体   繁体   English

如何在Swift中将值从自定义单元格设置/传递给ViewController

[英]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的金额吗?

How do I set/pass value to viewcontroller from table cell ?? 如何从表格单元格将值设置/传递给ViewController?

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.

相关问题 将数据从自定义单元格(在ViewController的表中)传递到ViewController本身Swift3 iOS - pass data from custom cell(in table which is on ViewController) to the viewcontroller itself Swift3 iOS 如何将值从ViewController传递到UITableView自定义单元格类 - how to pass Values from ViewController to UITableView custom cell class 斯威夫特:如何传递子视图控制器prepareForSegue的数据以更改父视图控制器表视图单元格的TextLabel? - Swift: How can I pass data from child viewcontroller prepareForSegue to change the TextLabel of a cell of parent viewcontroller tableview? 如何将值从嵌入式collectionView中的选定单元格传递到另一个viewController? - How to pass value from a selected cell in embedded collectionView to another viewController? 如何将数据从 ViewController 设置为 UITableView 自定义单元格 - How to set data from ViewController to UITableView custom Cell 如何将选定单元格的值传递给另一个ViewController? - How pass the value of a selected cell to another ViewController? Swift-我应该在哪里设置自定义单元格的值-CustomCell或ViewController? - Swift - Where should I set the values for custom cell - CustomCell or ViewController? 如何在swift中将自定义ViewController设置为UIAlertController的内容 - How to set custom ViewController as the content of UIAlertController in swift 如何将数据从单元格传递到另一个 ViewController - how to pass data from cell to another ViewController 如何快速将图像从一个视图控制器传递到另一个视图控制器? - How to pass an image from one viewcontroller to another viewcontroller in swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM