【发布时间】:2018-01-03 18:32:30
【问题描述】:
我准备了表格视图。如下图所示,有一个 sqllite db。 .但是搜索委托功能不起作用。
var dictionaries = [[String:AnyObject]]() //
var filteredDogs = [[String:AnyObject]]()
var searchController: UISearchController!
var resultsController = UITableViewController()
func updateSearchResultsForSearchController(searchController: UISearchController) {
self.filteredDogs = self.dictionaries.filter{(dict:[String:AnyObject]) -> Bool in
if dict.lowercaseString.containsString(self.searchController.searchBar.text!.lowercaseString)
{
return true
}
else
{
return false
}
}
//Update results table
self.resultsController.tableView.reloadData()
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! RowTableViewCell
if tableView == self.tableView
{
let row = self.dictionaries[indexPath.row]
cell.language1.text = row["foreign_language"] as? String
cell.language2.text = row["native_language"] as? String
}
else
{
let row = self.filteredDogs[indexPath.row]
cell.language1.text = row["foreign_language"] as? String
cell.language2.text = row["native_language"] as? String
}
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let row = self.dictionaries[indexPath.row]
self.speechText((row["foreign_language"] as? String)!, language: (row["language"] as? String)!)
let indexPath = self.tableView.indexPathForSelectedRow
if((indexPath) != nil){
self.tableView.deselectRowAtIndexPath(indexPath!, animated: true)
}
}
【问题讨论】:
-
您使用哪个数组来填充您的 UITableView?
-
字典 --> native_langauage 。 cell.language1.text = row["native_language"] as?字符串
-
你能把你所有的UITableView相关代码贴出来吗?
-
请用该代码编辑您的答案,在 cmets 中不可读
-
哦。对不起。我是论坛的新手。 :) 我添加到下面。你能检查一下吗?谢谢你
标签: ios swift xcode sqlite uitableview