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)
}
}
答案 0 :(得分:0)
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)
}
}