Answer the question
In order to leave comments, you need to log in
In ios11 searchBar's scopeButtons doesn't render correctly in tableHeaderView?
Good day, I'm learning to make IOS applications. Unfortunately, I did not find a decent book on ios11 - I am studying at https://www.ozon.ru/context/detail/id/140304577/. before that I mastered 4 Swift. There are some inconsistencies with api occasionally, but usually the problem with finding an analogue is solved in a couple of minutes.
Faced a problem
@IBOutlet weak var tableView: UITableView!
let sectionsTableIdentifier = "SectionsTableIdentifier"
var names: [String: [String]]!
var keys: [String]!
var searchController: UISearchController!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tableView.register(UITableViewCell.self, forCellReuseIdentifier: sectionsTableIdentifier)
let path = Bundle.main.path(forResource: "sortednames", ofType: "plist")
let nameDist = NSDictionary(contentsOfFile: path!)
names = nameDist as! [String:[String]]
keys = (nameDist!.allKeys as! [String]).sorted()
let resultsController = SearchResultsController()
resultsController.names = names
resultsController.keys = keys
searchController = UISearchController(searchResultsController: resultsController)
let searchBar = searchController.searchBar
searchBar.scopeButtonTitles = ["All", "Short", "Long"]
searchBar.placeholder = "Enter a search term"
searchBar.sizeToFit()
tableView.tableHeaderView = searchBar
searchController.searchResultsUpdater = resultsController
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question