我怎样才能调用搜索tableview委托与SQLLite
问题描述:
我准备了tableview。正如在下面的屏幕中,有一个sqllite db。 。但搜索委托功能不起作用。我怎样才能调用搜索tableview委托与SQLLite
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)
}
}
答
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相关的代码吗? –