简体   繁体   English

Swift-如何将数据从UITableViewCell类传递到UIViewController

[英]Swift - How to Pass Data From UITableViewCell Class to UIViewController

I was wondering how to pass data from a class that extends from UITableViewCell to a view controller? 我想知道如何将数据从从UITableViewCell扩展到视图控制器的类传递? I have some outlets on a custom cell connected to the UITableViewCell class that I would like to access from my UIViewController class. 我有一个自定义单元格上的一些插座,这些插座连接到UITableViewCell类,我想从我的UIViewController类访问这些插座。

Prepareforsegue only works for passing data between two viewcontrollers, so that does not apply to this case. Prepareforsegue仅适用于在两个视图控制器之间传递数据,因此不适用于这种情况。 All of the answers I have found on stack (and in various corners of the web) are in objective-c and no longer apply to swift. 我在堆栈上(以及在网络的各个角落)找到的所有答案都在Objective-C中,不再适用于swift。 I would really appreciate your help. 我将衷心感谢您的帮助。 Thanks. 谢谢。

Are you trying to access the UITableViewCell from the UIViewController where it is displayed? 您是否正在尝试从显示它的UIViewController访问UITableViewCell? If so, you should be able to access the outlets from your UITableViewCell using the dot operator. 如果是这样,您应该能够使用点运算符从UITableViewCell访问插座。

// Example In UIViewController
let customCell = UITableViewCell()  // This is whatever your custom cell is

let objectFromCell = customCell.outlet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Swift中将数据从UITableViewRowAction传递到UIViewController? - How to pass data to a UIViewController from a UITableViewRowAction in Swift? Swift-如何从UITableViewCell中的按钮调用UIVIewController - Swift - How call UIVIewController from a Button in UITableViewCell 如何将数据从 UITableViewCell 传输到另一个 UIViewController? - How to transfer data from a UITableViewCell to another UIViewController? 如何将UIViewController传递给Swift中的另一个类? - How to pass UIViewController to another class in Swift? 将数据从UITableViewCell可可触摸类传输到UIViewController类 - Transferring data from a UITableViewCell cocoa touch class to a UIViewController class 如何在 Swift 中的 UIViewController 和 NSObject 之间传递数据 - How to pass data between a UIViewController and an NSObject in Swift iOS Swift:将数据从ViewController传递到UITableViewCell - iOS Swift: Pass data from ViewController to UITableViewCell Swift-将UIVIewcontroller可变数组访问到UITableViewCell类 - Swift - Access UIVIewcontroller mutable array to UITableViewCell class 如何将数据从 UITableViewCell 传递到继承 NSObject 的 class - How to pass data from UITableViewCell to a class which inheritances NSObject 在Swift中将自定义UITableViewCell从笔尖加载到UIViewController - Loading a Custom UITableViewCell from nib to a UIViewController in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM