一恩闻、彈出窗口/底部窗口 didSelectRowat
1.Let xxx = UIAlertController(title: “”, message: “”, preferredStyle: )
2.let xxx = UIAlertAction(title: “”, style: .alert/.actionSheet, handler: )
3.xxx.addAction(xxx)
4.self.present(xxxs, animated:true, completion: nil)
二撬槽、右劃菜單 editActionsForRowAt
1.let xxx= UITableViewRowAction(style: , title: , handler:)
2.對handler閉包添加一種的兩種方式
3.刪除部分的源代碼
三溯革、轉(zhuǎn)場傳值
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == “xxxx” {
let xxx = segue.destination as! xxx
Xxx =? sender as! Xxx
}
}
四、模態(tài)化轉(zhuǎn)場
@IBAction func close(segue: UIStoryboardSegue) {
Let xxx = segue.source as! xxx
}
五枣察、模態(tài)化轉(zhuǎn)場傳值
performSegue(withIdentifier: "areaComment", sender: sender)
六呻待、刪除時候一定先刪除底層變量 在可視化部分刪除
七恃泪、退場 dismiss()
八、子頁面導(dǎo)航欄返回
let leftBarBtn = UIBarButtonItem(title: "返回", style: .plain, target: self,
action: #selector(backToPrevious))
tableViewCell 搜索相關(guān)數(shù)據(jù)
1.定義數(shù)組存放查找到的數(shù)據(jù)
var searchResults: [Area] = []
2.添加一個搜索依據(jù)方法
func searchFilter(text: String) {
searchResults = areas.filter({ (area) -> Bool in
return area.name!.localizedCaseInsensitiveContains(text)
})
}
3.執(zhí)行搜索方法
func updateSearchResults(for searchController: UISearchController) {
if let text = searchController.searchBar.text {
searchFilter(text: text)
tableView.reloadData()
}
}
4.根據(jù)搜索欄是否被激活顯示數(shù)據(jù)行數(shù)
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return searchController.isActive ? searchResults.count : areas.count
}
5.根據(jù)搜索欄是否被激活選擇相應(yīng)的顯示數(shù)據(jù)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let area = searchController.isActive ? searchResults[indexPath.row] : areas[indexPath.row]
}
6.根據(jù)搜索欄是否被激活選擇Cell是否能修改
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return !searchController.isActive
}
7.如果有轉(zhuǎn)場傳值的話需要相應(yīng)更改
搜索條美化
// 搜索條美化之后背景不變黑坐儿,且可以點擊搜索數(shù)據(jù)
searchController.searchBar.dimsBackgroundDuringPresentation = false
// 搜索條占位符
searchController.searchBar.placeholder = ""
// 搜索條提示
searchController.searchBar.prompt
// 搜索條前景色
searchController.tintColor
// 搜索條主題樣式(默認.Prominent(突出) .Minimal(透明))
searchController.searchBar.searchBarStyle