ios - 如何在快速单击按钮时获取 tableview 标签值

标签 ios swift uitableview

我是 swift 的新手,我想在单击按钮时从 tableview 中获取标签的值

我正在使用这样的代码,但它正在崩溃

在 cellforrowatindexpath 中

 cell.btnsubmit.tag = indexPath.row
        cell.btnsubmit.addTarget(self, action: #selector(buttonSelected), for: .touchUpInside)

@objc func buttonSelected(sender: UIButton){
        print(sender.tag)

         let cell = sender.superview?.superview as! PatientUpdateVCCell

         surgery_date = cell.surgeryDateTextField.text!
         discharge_date = cell.dischargeDateTextField.text!
         follow_up_duration = cell.lblfolowup.text!
         follow_up_date = cell.firstFollowUpTextField.text!
         patient_status = cell.patientStatusTextView.text!

    }

但它正在崩溃。我怎样才能做到这一点

崩溃

Could not cast value of type 'UITableViewCellContentView' (0x11a794af0) to 'appname.PatientUpdateVCCell' (0x10ae74ae0).

最佳答案

根据你的崩溃,最后一个 superView 是 contentView 然后它的 superView 是需要的单元格,所以你需要

let cell = sender.superview!.superview!.superview as! PatientUpdateVCCell

关于ios - 如何在快速单击按钮时获取 tableview 标签值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59197195/

相关文章:

swift - 如何按数字和字母拆分字符串

ios - AVPlayer 无法播放 HLS 直播

iphone - 在选择时更改 UITableViewCell 布局

ios - 在应用程序中收到通知时,PFInstallation 不是最新的

swift - Xcode 6.3 中的 Git : Master branch showing new files from other branches in red and won't compile

android - 检查unity3D(iOS,Android)中是否有SMS

ios - 如何从 UIView 子类调用 UIViewController?

ios - 为什么 UITableView 位于 TabBar 下方?

ios - 将 AudioKit 麦克风连接到 Google Speech-to-Text

ios - 删除 Swift 3 中的最后一个字符