This is not the code, it is something you have edited (line 109, 123, …)
So please copy the exact code.
And use Paste and match style to avoid all the extra lines, like this:
class SearchCell: UITableViewCell, UISearchBarDelegate {
let searchbar = UISearchBar()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
addSubview(searchbar)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setConstraints() {
searchbar.placeholder = "Country, City"
searchbar.searchBarStyle = .minimal
let TapGesture = UITapGestureRecognizer(target: self, action: #selector(searchBarTapped))
searchbar.addGestureRecognizer(TapGesture)
searchbar.isUserInteractionEnabled = true
// Constraints
searchbar.translatesAutoresizingMaskIntoConstraints = false
searchbar.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
searchbar.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10).isActive = true
searchbar.widthAnchor.constraint(equalToConstant: 380).isActive = true
searchbar.heightAnchor.constraint(equalToConstant: 40).isActive = true
}
@objc func searchBarTapped() {
searchbar.delegate = self
}
override func awakeFromNib() {
super.awakeFromNib() {
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
Why do you set the delegate in searchBarTapped() ?
That's too late.
You should have done it earlier, probably in awake or in init.
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: