gpt4 book ai didi

swift - 将按钮放在 tableview 单元格上时崩溃,无法识别的选择器

转载 作者:行者123 更新时间:2023-11-28 06:44:18 25 4
gpt4 key购买 nike

PatientTableViewCell viewBtn:]: unrecognized selector sent to instance 0x7fdde280ac00

libc++abi.dylib: terminating with uncaught exception of type NSException

有什么想法吗?谢谢

   func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let current_patient = patients[indexPath.row]
let cell = myTable.dequeueReusableCellWithIdentifier("patientCell", forIndexPath: indexPath) as! PatientTableViewCell
let type = current_patient.enrollable_type
var unique_id = current_patient.unique_id
cell.patientTypelbl.text = type
cell.patientIDlbl.text = unique_id
cell.viewBtn.tag = indexPath.row
cell.viewBtn.addTarget(self, action: "viewDetailAction:", forControlEvents: .TouchUpInside)
return cell
}

@IBAction func viewDetailAction(sender: UIButton){
print("clicked")
self.performSegueWithIdentifier("patientDetailCell", sender: self)
}

对于 patientTableviewcell:

 class PatientTableViewCell: UITableViewCell {

@IBOutlet weak var viewBtn: UIButton!
@IBOutlet weak var titleType: UILabel!
@IBOutlet weak var titleID: UILabel!
@IBOutlet weak var patientTypelbl: UILabel!
@IBOutlet weak var patientIDlbl: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

最佳答案

您的错误是在 xCode 编辑器中设置了一个 IBAction,然后以编程方式将选择器目标添加到同一按钮。

首先从 Referencing Outlets 中删除您的 IBAction 设置,如图中所示:

enter image description here

之后,您必须通过删除 IBAction 标记来重命名您的函数:

func viewDetailAction() {...}

关于swift - 将按钮放在 tableview 单元格上时崩溃,无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37000560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com