【发布时间】:2020-07-20 07:39:24
【问题描述】:
我正在按照 raywenderlich.com 教程显示我的表格的搜索栏,但我在任何地方都看不到它(是的,我向上滚动)
这是我的代码:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchControllerDelegate, UISearchResultsUpdating {
@IBOutlet weak var tableView: UITableView!
func updateSearchResults(for searchController: UISearchController) {
let searchBar = searchController.searchBar
filterContentForSearchText(searchBar.text!)
}
var isSearchBarEmpty: Bool {
return searchController.searchBar.text?.isEmpty ?? true
}
func filterContentForSearchText(_ searchText: String) {
filteredStrings = stockArr.filter { (string: String) -> Bool in
return string.lowercased().contains(searchText.lowercased())
}
tableView.reloadData()
}
var filteredStrings: [String] = []
var searchController : UISearchController!
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Candies"
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
definesPresentationContext = true
}
}
请帮助我,我已经尝试了所有 StackOverflow 解决方案,但没有任何效果,这段代码与我之前的普通 tableview 没有什么不同。
【问题讨论】:
-
你能分享你关注的链接吗?
-
@SMAbuTaherAsif raywenderlich.com/…
标签: ios swift xcode tableview uisearchcontroller