gpt4 book ai didi

swift - #selector 未解析的标识符函数

转载 作者:行者123 更新时间:2023-12-04 17:42:32 26 4
gpt4 key购买 nike

在 init 函数中,#selector 似乎找不到调用函数。

这是类

import UIKit

protocol ExpandableHeaderViewDelegate {
func toggleSection(header: ExpandableHeaderView, section: Int)
}

class ExpandableHeaderView: UITableViewHeaderFooterView {
var delegate: ExpandableHeaderViewDelegate?
var section: Int!

@IBOutlet weak var titleLabel: UILabel!

override init(reuseIdentifier: String?){
super.init(reuseIdentifier: reuseIdentifier)
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectHeaderView(_:))))

}

@objc func selectHeaderView(gesture: UITapGestureRecognizer){
let cell = gesture.view as! ExpandableHeaderView
delegate?.toggleSection(header: self, section: cell.section)
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectHeaderView(_:))))
}


func custonInt(title: String, section: Int, delegate: ExpandableHeaderViewDelegate){

self.titleLabel.text = title
self.section = section
self.delegate = delegate
}

override func layoutSubviews(){
super.layoutSubviews()
self.titleLabel.textColor = UIColor.white
self.contentView.backgroundColor = UIColor.darkGray
}

这里是错误:

Use of unresolved identifier 'selectHeaderView'

初始化函数添加手势识别器找不到selectHeaderView。它的行为就好像它不是类(class)的一部分。我做错了什么?

最佳答案

改变这个:

self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectHeaderView(_:))))

到:

self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectHeaderView(gesture:))))

关于swift - #selector 未解析的标识符函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53826013/

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