在我经历的所有错误中,这是迄今为止最奇怪的。在我的自定义UITableViewCell类中,我有此方法:
@IBOutlet weak var searchButton: UIButton!
@IBOutlet weak var backButton: UIButton!
@IBOutlet weak var title: UILabel!
var onMorePressed : (() -> Void)? = nil
var onBackPressed : (() -> Void)? = nil
var onSearchPressed : (() -> Void)? = nil
@IBAction func searchButtonPressed(_ sender: Any) {
if searchButton.imageView?.image == UIImage(named : "searchwhite"){
if let tapped = onSearchPressed{
tapped()
}
}else{
if let tapped = onMorePressed{
tapped()
}
}
}
搜索在此处的cellForRowAt中处理:
cell.backgroundColor = .clear
cell.selectionStyle = .none
cell.searchButton.isUserInteractionEnabled = true
cell.searchButton.isHidden = false
cell.onSearchPressed = {
self.showSearchScreen()
}
该按钮将按预期工作,直到您关闭(而不是终止)该应用程序为止。当返回到前台时,该按钮将变得无用。为什么是这样?这太奇怪了,我尝试在进入前台时重新加载tableView,但这没有用。