나는 답을 찾고 있었고 도와 주셨으면합니다. 코드에서 실수는 보이지 않지만 "검색"버튼을 누르면 UISearchBarDelegate가 작동하지 않습니다. UISearchBarDelegate 검색 버튼이 작동하지 않습니다. 3 iOS 10.3
이
이 그냥 추측 내 수업class BusquedaViewController: UIViewController, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var searchBar: UISearchBar!
var referencias: [Reference]!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 200, height: 20))
searchBar.tintColor = UIColor.white
searchBar.delegate = self
self.parent?.navigationItem.titleView = searchBar
referencias = DataManager.sharedInstance.obtenerReferencias()
}
override func viewWillAppear(_ animated: Bool) {
self.parent?.title = "Busqueda"
}
//MARK: UISearchBar
func searchBar(_ searchBar: UISearchBar, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
var placa = searchBar.text
if text.isEmpty {
return true
} else {
let uper = text.uppercased()
let allowed = "1234567890ABCDEFGHIJKLMNÑOPQRSTUVWXYZ-"
if !allowed.contains(uper) || (placa?.characters.count)! > 9 {
return false
}
searchBar.text = searchBar.text! + uper
return false
}
}
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
searchBar.showsCancelButton = true
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
searchBar.showsCancelButton = false
searchBar.text = ""
searchBar.endEditing(true)
}
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.endEditing(true)
}
//MARK: UITableView
func numberOfSections(in tableView: UITableView) -> Int {
return referencias.isEmpty ? 1 : referencias.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
if referencias.isEmpty {
//cell.textLabel?.text = NSLocalizedString("NO_REFERENCIAS", comment: "")
} else {
cell.textLabel?.text = referencias[indexPath.row].model
}
return cell
}
}
다른 대표가 호출되거나 –
Storyboard가 아닌 코드를 통해 검색 표시 줄을 추가 하시겠습니까? – CodeChanger
실제로 "searchBarSearchButtonClicked"를 제외한 모든 것이 작동합니다 –