開始研究大數(shù)據(jù)方面了,留下我最近的記錄(Swift各種轉(zhuǎn)場和搜索控件的使用)

一、彈出窗口/底部窗口 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.對(duì)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)

六、刪除時(shí)候一定先刪除底層變量 在可視化部分刪除

七、退場 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.添加一個(gè)搜索依據(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)更改

搜索條美化

// 搜索條美化之后背景不變黑,且可以點(diǎn)擊搜索數(shù)據(jù)

searchController.searchBar.dimsBackgroundDuringPresentation = false

// 搜索條占位符

searchController.searchBar.placeholder = ""

// 搜索條提示

searchController.searchBar.prompt

// 搜索條前景色

searchController.tintColor

// 搜索條主題樣式(默認(rèn).Prominent(突出) .Minimal(透明))

searchController.searchBar.searchBarStyle

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容